[.net] ADO (6.0) + ODBC드라이버를 이용한 DB Connection (MS-SQL, Excel, Access)
Microsoft ActiveX Data Objects 6.0 Library (adodb)와 ODBC 를 이용해서 각 DB에 Connection하는 클래스
Public Class DBConn Public myDB As New ADODB.Connection Public myRS As New ADODB.Recordset Public qq As StringBuilder Public Function DBOpen() As Boolean Dim Opened As Boolean Try myDB.Open("Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=111.111.111.111,1111;Initial Catalog=DBNAME;User ID=DBNAME;Password=DBPASS;") If myDB.State Then Opened = True Else Opened = False End If Catch ex As Exception Opened = False End Try myRS.CursorType = ADODB.CursorTypeEnum.adOpenStatic myRS.CursorLocation = ADODB.CursorLocationEnum.adUseClient myRS.LockType = ADODB.LockTypeEnum.adLockOptimistic DBOpen = Opened End Function Public Sub DBClose() Try myDB.Close() loFunctions.releaseObject(myDB) Catch ex As Exception End Try End Sub End Class Public Class xlDBConn Public xlDB As New ADODB.Connection Public xlRS As New ADODB.Recordset Public qq As StringBuilder Public Function xlDBOpen(xlFileNM As String) As Boolean Dim Opened As Boolean Try With xlDB .ConnectionString = "Dsn=Excel Files;dbq=" + xlFileNM + ";driverid=1046;fil=excel 12.0;maxbuffersize=2048;pagetimeout=5" .Open() End With If xlDB.State Then Opened = True Else Opened = False End If Catch ex As Exception Opened = False End Try xlDBOpen = Opened End Function Public Sub xlDBClose() Try xlDB.Close() loFunctions.releaseObject(xlDB) Catch ex As Exception End Try End Sub End Class Public Class aceDBConn Public aceDB As New ADODB.Connection Public aceRS As New ADODB.Recordset Public qq As StringBuilder Public Function aceDBOpen(aceFileNM As String) As Boolean Dim Opened As Boolean Try With aceDB .ConnectionString = "Dsn=MS Access Database;dbq=" + aceFileNM.Replace("\\", "\") + ";driverid=25;fil=MS Access;maxbuffersize=2048;pagetimeout=5;uid=admin" .Open() End With If aceDB.State Then Opened = True Else Opened = False End If Catch ex As Exception Opened = False End Try aceDBOpen = Opened End Function Public Sub aceDBClose() Try aceDB.Close() loFunctions.releaseObject(aceDB) Catch ex As Exception End Try End Sub End Class
'.NET Develop > Develop' 카테고리의 다른 글
[.NET] 파일 이름 변경, 복사할 때 동일한 파일이 있으면 자동으로 넘버링 해 주기. (1) | 2013.11.08 |
---|---|
[vb.NET] Tab 파일을 XLSX로 변환 (1) | 2013.09.30 |
[.Net] Datatable을 Access에 Insert하는 방법. (Bulk Insert) (1) | 2013.09.04 |
[.NET] 디렉토리의 파일 목록 조사 + 필터링. Linq와 람다식을 이용한 Directory.GetFiles 확장자 지정하기. (0) | 2013.04.04 |
[.NET] 시스템 환경변수 Path에 특정 경로 추가하기. (1) | 2013.02.21 |