我创建了一个这样的数据库:
Sub Main()
Dim wrkDefault As Workspace
Dim dbE As DBEngine
Dim dbs As Database
'Get default Workspace.
dbE = New DBEngine
wrkDefault = dbE.Workspaces(0)
'Set the database filename
Dim DBFilename As String
DBFilename = "c:\mydb.mdb"
'Make sure there isn't already a file with the same name of
'the new database file.
If Dir(DBFilename) <> "" Then
MsgBox("File already exists!")
Exit Sub
End If
'Create a new encrypted database with the specified
'collating order.
'lock database with the password 'hello'
dbs = wrkDefault.CreateDatabase(DBFilename, _
LanguageConstants.dbLangGeneral & ";pwd=hello;", DatabaseTypeEnum.dbEncrypt)
dbs.Close()
End Sub
如何使用DAO在VB.NET中再次打开此数据库?
答案 0 :(得分:2)
Dim cn As New ADODB.Connection
cn.Provider = "Microsoft Jet 4.0 OLE DB Provider"
cn.ConnectionString = "Data Source=c:\db1.mdb"
cn.Properties("Jet OLEDB:Database Password") = "mypwd"
cn.Open
对于DAO,连接字符串很可能看起来像这样:
ODBC;DSN=DSNname;DATABASE=DBname;UID=SQLUser;PWD=SQLpassword;
或者像这样:
Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=C:\...\NWind.mdb;" & _
"UID=admin;PWD=password;"
对于第一个字符串,您必须使用“控制面板”/“管理工具”/“ODBC源”创建数据源名称(DSN)文件。第二个字符串不需要DSN连接。现在你知道他们为什么发明了ADO.NET。