我有一个访问密码保护的数据库。 我正在使用Visual Studio 2010和ODBC。
必须添加哪些代码才能成功连接到受保护的文件?
我正在使用此代码:
Imports System.Data.Odbc
Imports System
Public Class DatabaseFunctions
Shared con As OdbcConnection
Public Shared Sub CreateConnection()
con = New OdbcConnection
con.ConnectionString = "Dsn=XXX"
con.Open()
End Sub
Private Shared Sub CheckConnection()
If con Is Nothing OrElse con.State = ConnectionState.Closed Then
CreateConnection()
End If
End Sub
End Class
答案 0 :(得分:2)
将此添加到您的CreateConnection()函数代码:
Public Shared Sub CreateConnection()
con = New OdbcConnection
'con.ConnectionString = "Dsn=XXX"
con.ConnectionString = "Dsn=XXX;uid=sa;pwd=passwordRIGHT;"
con.Open()
End Sub
Here是几种dbs的方法