問:CnStr = "PROVIDER=SQLOLEDB;DATA SOURCE=(local);UID="";PWD="";DATABASE=yaopin"
Set Conn = New ADODB.Connection
With Conn
.ConnectionString = CnStr
.Open CnStr
End With
我的SQL數據庫沒有用戶名和密碼,怎麼寫
答:
給個例子你參考一下:
Sub Main()
On Error GoTo On_error
'frmWelcome.Show
Set con = New ADODB.Connection
con.ConnectionString = ("Provider=SQLOLEDB;User ID=sa;PWD=;Initial Catalog=human;Data Source=.")
con.Open
con.CommandTimeout = 20
Load frmLogin
frmLogin.Show vbModal
Exit Sub
On_error:
If Err.Number = -2147467259 Or Err.Number = -2147217900 Then
Unload frmWelcome
MsgBox "檢查到 SQL Server 未安裝或軟件所需數據庫未安裝..." & vbCrLf & "正在進一步檢查 SQL Server 的安裝情況,若已啟動則開始安裝數據庫... ", vbInformation + vbOKOnly, "系統提示"
Shell (App.Path & "\Installdb.exe")
End
Else
MsgBox Err.Number & Err.Description, vbInformation + vbOKOnly, "系統提示"
End
End If
End Sub