工程文件在D盘,数据库文件也在D盘Public Sub Main() g_DBPath = App.Path & "\Database\ManageClient.mdb" 'MsgBox g_DBPath If ConnectToDatabase(DBAccess) = False Then Err.Raise vbObjectError + 1, , "连接数据库出错!|" + App.Path + "|" End If End Sub'连接到数据库 Public Function ConnectToDatabase(DBType As gxcDBType) As Boolean On Error GoTo ERR_CONN Set g_Conn = New Connection
'设置服务器名称,数据库名称,登录名(此时假设密码为空) Dim ServerName As String, DBName As String, UserName As String, strPwd As String '这些是为连接Sql Server而用 ServerName = "localhost" DBName = "ManageClient" UserName = "sa" strPwd = ""
'连接到数据库 With g_Conn .CursorLocation = adUseClient .CommandTimeout = 10
If DBType = DBAccess Then ' 连接到ACCESS数据库 .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password='';" & _ "Data Source=" & g_DBPath Else ' 连接到SQL Server数据库 .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _ "User ID=" & UserName & ";Initial Catalog=" & DBName & _ ";Data Source=" & ServerName & ";pwd=" & strPwd End If .Open End With ConnectToDatabase = True Exit Function
g_DBPath = App.Path & "\Database\ManageClient.mdb"
'MsgBox g_DBPath
If ConnectToDatabase(DBAccess) = False Then
Err.Raise vbObjectError + 1, , "连接数据库出错!|" + App.Path + "|"
End If
End Sub'连接到数据库
Public Function ConnectToDatabase(DBType As gxcDBType) As Boolean
On Error GoTo ERR_CONN
Set g_Conn = New Connection
'设置服务器名称,数据库名称,登录名(此时假设密码为空)
Dim ServerName As String, DBName As String, UserName As String, strPwd As String
'这些是为连接Sql Server而用
ServerName = "localhost"
DBName = "ManageClient"
UserName = "sa"
strPwd = ""
'连接到数据库
With g_Conn
.CursorLocation = adUseClient
.CommandTimeout = 10
If DBType = DBAccess Then
' 连接到ACCESS数据库
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password='';" & _
"Data Source=" & g_DBPath
Else
' 连接到SQL Server数据库
.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
"User ID=" & UserName & ";Initial Catalog=" & DBName & _
";Data Source=" & ServerName & ";pwd=" & strPwd
End If
.Open
End With
ConnectToDatabase = True
Exit Function
ERR_CONN:
ConnectToDatabase = False
MsgBox Err.Description
End Function
打包有问题。
换个吧,我现在用setupfactory