怎样连接 局域网上的 SQL 2000 数据库

zzzwwwllll 2004-09-27 11:26:31
怎样连接 局域网上的 SQL 2000 数据库
...全文
150 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
射天狼 2004-09-28
'工程->引用->Microsoft ActiveX Data Objects 2.0 Library (后面为版本号)
Dim rs As New ADODB.Recordset, cn As New ADODB.Connection

'向数据库中添加数据
Private Sub Command2_Click()
If rs.State = adStateOpen Then rs.Close
rs.Open "SELECT * FROM USERPASSWORD", cn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs!UID = txtUid.Text
rs!PWD = txtPwd.Text
rs!TRUENAME = txtName.Text
rs!CREATEDATE = Format(Now, "YYYY/MM/DD")
rs.Update

Command1.Value = True
End Sub

'从数据库中删除数据
Private Sub Command3_Click()
cn.Execute "DELETE FROM USERPASSWORD WHERE UID = '" & txtUid.Text & "'"
Command1.Value = True
End Sub

Private Sub Form_Load()
cn.ConnectionString = "Driver={SQL Server};SERVER=192.168.2.88;DATABASE=zxzx;UID=information;PWD=information*&#"
cn.Open
'查询字符串可以上这里查
'http://www.connectionstrings.com/
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
On Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
回复
wangquansh 2004-09-28
sconn = "Driver={SQL Server};Server=服务器;Database=数据库名称;Uid=用户名;Pwd=密码;"

如果是局域网中的机器那么:
sconn = "Driver={SQL Server};Server=机器名称;Database=数据库名称;Uid=用户名;Pwd=密码;"
回复
wangquansh 2004-09-28
Dim rstClient As ADODB.Recordset
Set rstClient = New ADODB.Recordset
Dim sconn As String
sconn = "Driver={SQL Server};Server=服务器;Database=数据库名称;Uid=用户名;Pwd=密码;"

rstClient.CursorLocation = adUseClient
rstClient.CursorType = adOpenKeyset
rstClient.LockType = adLockOptimistic

rstClient.Open "select * from 表名", sconn, , , adCmdText
回复
yijiansong 2004-09-28
是不是想在外网上连接 局域网上的 SQL 2000 数据库?
回复
ryuginka 2004-09-28
Data Source=服务器名
回复
fabiaowanming 2004-09-28
dim cn as new adodb.connection
cn.connectionstring="PROVIDER=SQLOLEDB;SERVER=server 名;DATABASE=数据库名;Integrated Security=SSPI"
cn.open
加上 Integrated Security=SSPI 说明是NT 域认证。
回复
tztz520 2004-09-28
Dim xx As String
gDBConnect.CommandTimeout = 10
xx = "Provider=sqloledb;Data Source=192.168.1.200;Initial Catalog=" & "csdb" & ";User Id=sa;Password=1234"
gDBConnect.ConnectionString = xx
gDBConnect.Open
回复
zichen66 2004-09-28
1.ODBC的方式
uid=sa;pwd=;driver={SQL Server};server=服务器名或IP;database=库名
2.OLEDB的方式
Provider=SQLOLEDB.1;User ID=sa;Password=;Initial Catalog=数据库名;Data Source=服务器名或IP

另外:在聯接時默認的游標類型是<客戶端>的
回复
sunmoonn 2004-09-28
dim conn As New ADODB.Connection
dim rs As New ADODB.Recordset
conn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
"User ID=sa;Password=;Initial Catalog=数据库名;Data Source=服务器名"
conn.Open
rs.open "select * form 表",conn,3,3
'--------------------------------
http://www.connectionstrings.com/
回复
hzybc 2004-09-28
Set CN = New ADODB.Connection
With CN
.ConnectionString = "uid=sa;pwd=;driver={SQL Server};server=IP地址;database=库名
.ConnectionTimeout = 30
.Open
End With

局域网中也可以将IP地址改为机器名
回复
发动态
发帖子

1180

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
社区公告
暂无公告