通过ADO连接服务器上的数据库为什么不能成功
编号:QA004232
建立日期: 2001年6月4日 最后修改日期:2001年8月19日
所属类别:
shitao:
操作系统: windows2000(server),windows98(client)
编程工具: vb6,sqlserver7.0
问题:
我使用VB6和SQLSERVER7进行C/S编程,数据库在服务器端,我的编程是在客户机上进行,我想用ADO,从VB6连接服务器上的数据库。
简单的程序:
dim cn as adodb.connection
set cn =new adodb.connection
dim strCn as string
strCN="Provider=SQLOLEDB.1;UID=sa;PWD=;data Source=\\compserver\mssql7\data\comp.mdb"
cn.open strCN
使用以上方法,无法打开连接。
水平: 中级
回答:
无法打开连接原因:SQL Server不能直接链接到某个文件名。
正确格式如下://每个小內容均以分号結束,且口令一般不能为空
strCN="Driver={SQL Server};Server=服务器名;DataBase=数据库;UID=用户;PWD=口令;"
eg:SQL服务器名为 WEBSVR,数据库名为WebMis(在SQL Enterprise Manager中查看到),用户sa,口令123,则以上为:
strCN="Driver={SQL Server};Server=WEBSVR;DataBase=WebMis;UID=sa;PWD=123;"
更多可參考http://xufb.top263.net/vb/vb009.htm
乐言的意见:
Dim connLocal As New ADODB.Connection
Dim rsLocal As New ADODB.Recordset
dim g_gonn as string
'数据源连接字符串
g_Conn = "DSN=yizanNews;UID=sa;PWD=12332132"
connlocal.open g_conn
tempStr = "select * from table1"
'将记录集给rslocal对象。
rsLocal.open connLocal,tempStr
'然后用recordset的方法对数据集操作。
'如:rslocal.movefirst。。。。。。
此问题由Frank Xu回答。
| |
|
|
| |
|
|