質問するログイン新規登録

質問編集履歴

2

コメントの指摘に基づき内容を追記。

2019/03/27 08:02

投稿

heart_crimson
heart_crimson

スコア15

title CHANGED
File without changes
body CHANGED
@@ -26,7 +26,105 @@
26
26
  ### 該当のソースコード
27
27
 
28
28
  ```DBAccessDapper
29
+ Imports System.IO
30
+ Imports System.Reflection
31
+ Imports MyProject.Utils
32
+ Imports Dapper
33
+ Imports Npgsql
34
+
35
+ Namespace Database
36
+
37
+ Public Class DBAccessDapper
38
+ Implements IDisposable
39
+
40
+ #Region "定数"
41
+
42
+ Private Const DATABASE_ENCODING As String = "UTF8"
43
+
44
+ #End Region
45
+
46
+ #Region "Private変数"
47
+
48
+ Private Connection As IDbConnection
49
+ Private Transaction As IDbTransaction
50
+ Private Shared _DbConfigData As DbConfigData
51
+ Private ReadOnly Property IsConnected As Boolean
52
+ Get
53
+ Return If(Connection IsNot Nothing, Connection.State = ConnectionState.Open, False)
54
+ End Get
55
+ End Property
56
+
57
+ #End Region
58
+
59
+ #Region "Publicメソッド"
60
+
29
61
  ''' <summary>
62
+ ''' コンストラクタ
63
+ ''' </summary>
64
+ Public Sub New()
65
+ Try
66
+ DefaultTypeMap.MatchNamesWithUnderscores = True
67
+ GetDbConfiData()
68
+ Open()
69
+ Catch ex As Exception
70
+ Throw New Exception("接続に失敗しました。" & " : " & ex.Message, ex)
71
+ End Try
72
+ End Sub
73
+
74
+ ''' <summary>
75
+ ''' コンストラクタ
76
+ ''' </summary>
77
+ Public Sub New(ByVal hostName As String, ByVal port As Integer, ByVal userName As String, password As String, ByVal databaseName As String)
78
+ Try
79
+ DefaultTypeMap.MatchNamesWithUnderscores = True
80
+ Open(hostName, port, userName, password, databaseName)
81
+ Catch ex As Exception
82
+ Throw New Exception("接続に失敗しました。" & " : " & ex.Message, ex)
83
+ End Try
84
+ End Sub
85
+
86
+ ''' <summary>
87
+ ''' データベースへの接続処理
88
+ ''' ※接続情報を設定ファイルから取得
89
+ ''' </summary>
90
+ Public Sub Open()
91
+ Open(_DbConfigData.ServerName, _DbConfigData.Port, _DbConfigData.UserId, _DbConfigData.Password, _DbConfigData.DatabaseName)
92
+ End Sub
93
+
94
+ ''' <summary>
95
+ ''' データベースへの接続処理
96
+ ''' ※接続情報を引数から取得
97
+ ''' </summary>
98
+ ''' <param name="hostName">ホスト名</param>
99
+ ''' <param name="port">ポート</param>
100
+ ''' <param name="userName">ユーザー名</param>
101
+ ''' <param name="password">パスワード</param>
102
+ ''' <param name="dbName">データベース名</param>
103
+ Public Sub Open(ByVal hostName As String, ByVal port As Integer, ByVal userName As String, password As String, ByVal dbName As String)
104
+ If Connection Is Nothing Then Connection = New NpgsqlConnection
105
+
106
+ Dim connStrBuilder As New NpgsqlConnectionStringBuilder
107
+ Try
108
+ '接続情報の設定
109
+ connStrBuilder.Host = hostName
110
+ connStrBuilder.Port = port
111
+ connStrBuilder.UserName = userName
112
+ connStrBuilder.Password = password
113
+ connStrBuilder.Database = dbName
114
+
115
+ '接続文字列の作成
116
+ Connection.ConnectionString = connStrBuilder.ToString
117
+
118
+ '接続
119
+ Connection.Open()
120
+ Catch ex As Exception
121
+ Throw New Exception("接続に失敗しました。" & " : " & ex.Message & "|" & connStrBuilder.ToString, ex)
122
+ End Try
123
+ End Sub
124
+
125
+ ~省略~
126
+
127
+ ''' <summary>
30
128
  ''' SQLの実行(SELECT)
31
129
  ''' </summary>
32
130
  ''' <typeparam name="T"></typeparam>
@@ -83,4 +181,5 @@
83
181
 
84
182
  VB 2012
85
183
  .NET Framework 4
86
- Postgresql 9.3
184
+ Postgresql 9.3
185
+ Windows Forms使用

1

タグを変更。

2019/03/27 08:01

投稿

heart_crimson
heart_crimson

スコア15

title CHANGED
File without changes
body CHANGED
File without changes