如何打开SQLServer2000数据库
- VB code
Set g_conn = New Connection ServerName = "localhost" DBname = "mytest" UserName = "sa" strPwd = ""with g_conn .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _ "User ID=" & UserName & ";Initial Catalog=" & DBname & _ ";Data Source=" & ServerName & ";pwd=" & strPwdend with
以上连接数据库是对连接字符串属性的赋值,程序执行之后连接字符串的正确值是:
Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=mytest;Data Source=localhost;pwd=
但是这个值是错误的,请问正确的应该怎么写,谢谢!!
[解决办法]
经测试你的连接语句没有问题,但要保证你的数据库sa没有密码(sql安全性里面去设置)
- VB code
Private Sub Form_Load() Dim g_conn As New ADODB.Connection Dim g_rst As New ADODB.Recordset ServerName = "localhost" DBname = "hyel" '"mytest" UserName = "sa" strPwd = "" With g_conn .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _ "User ID=" & UserName & ";Initial Catalog=" & DBname & _ ";Data Source=" & ServerName & ";pwd=" & strPwd End With g_conn.CursorLocation = adUseClient g_conn.Open g_rst.Open "select * from zd_yhb", g_conn, adOpenStatic, adLockPessimistic Set DataGrid1.DataSource = g_rstEnd Sub