主题:求助VB链接SQL 2000 数据库问题!急!!!
Public PublicStr As String
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str As String
Dim Server As String
Dim uid As String
Dim pwd As String
Public Sub main()
'读取数据库配置文件
Open (App.Path & "\DataBase.ini") For Input As #1
Line Input #1, Intext
Server = Mid(Intext, 10, Len(Trim(Intext)) - 9)
Line Input #1, Intext
uid = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Line Input #1, Intext
pwd = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Close #1
'附加数据库
On Error Resume Next
con.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & uid & ";PWD=" & pwd & ";"
con.Open '打开数据库连接
Set rs = New ADODB.Recordset
'开始附加数据库
Str = "EXEC sp_attach_db @dbname = N'db_OA', @filename1 = N'" + App.Path + "\DataBase\db_OA_Data.MDF" + "', @filename2 = N'" + App.Path + "\DataBase\db_OA_Log.LDF" + "'"
' rs.Open str, con, 1, adLockOptimistic
Set rs = con.Execute(Str)
con.Close '关闭数据库连接
'共享连接字符串
PublicStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & uid & ";PWD=" & pwd & ";Initial Catalog=db_OA;Data Source=" & Server & ""
frm_login.Show
End Sub
Private Sub labLogin_Click()
adoLogin.ConnectionString = PublicStr
adoLogin.RecordSource = "select * from tbOA_user where username='" + Text1.Text + "' and userpwd='" + Text2.Text + "'"
adoLogin.Refresh
调试到这时出现“无法打开登录‘db_OA’中请求的数据库,登录失败”
请问怎么解决!数据库文件都在……急!!!
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Str As String
Dim Server As String
Dim uid As String
Dim pwd As String
Public Sub main()
'读取数据库配置文件
Open (App.Path & "\DataBase.ini") For Input As #1
Line Input #1, Intext
Server = Mid(Intext, 10, Len(Trim(Intext)) - 9)
Line Input #1, Intext
uid = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Line Input #1, Intext
pwd = Mid(Intext, 7, Len(Trim(Intext)) - 6)
Close #1
'附加数据库
On Error Resume Next
con.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & uid & ";PWD=" & pwd & ";"
con.Open '打开数据库连接
Set rs = New ADODB.Recordset
'开始附加数据库
Str = "EXEC sp_attach_db @dbname = N'db_OA', @filename1 = N'" + App.Path + "\DataBase\db_OA_Data.MDF" + "', @filename2 = N'" + App.Path + "\DataBase\db_OA_Log.LDF" + "'"
' rs.Open str, con, 1, adLockOptimistic
Set rs = con.Execute(Str)
con.Close '关闭数据库连接
'共享连接字符串
PublicStr = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & uid & ";PWD=" & pwd & ";Initial Catalog=db_OA;Data Source=" & Server & ""
frm_login.Show
End Sub
Private Sub labLogin_Click()
adoLogin.ConnectionString = PublicStr
adoLogin.RecordSource = "select * from tbOA_user where username='" + Text1.Text + "' and userpwd='" + Text2.Text + "'"
adoLogin.Refresh
调试到这时出现“无法打开登录‘db_OA’中请求的数据库,登录失败”
请问怎么解决!数据库文件都在……急!!!