首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

vb连接sql2005数据库时候异常-2147467259 (80004005)

2012-03-22 
vb连接sql2005数据库时候错误-2147467259 (80004005)Public connAs New ADODB.ConnectionPublic rsAs New

vb连接sql2005数据库时候错误-2147467259 (80004005)
Public conn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public addFlag As Boolean


Public Function OpenCn() As Boolean
Dim mag As String
'On Error GoTo strerrmag
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.ConnectionTimeout = 25
conn.Provider = "sqloledb "
conn.Properties("data source").Value = "127.0.0.1:1433" '服务器的名字
conn.Properties("initial catalog").Value = "Emp" '库名
conn.Properties("integrated security").Value = "SSPI" '登陆类型
  conn.Properties("user id").Value = sa
  conn.Properties("password").Value = sa
conn.Open
OpenCn = True
addFlag = True
If OpenCn = True Then
MsgBox "连接成功,请输入语句进行查询 ", vbDefaultButton1, "连接状态 "
Else: GoTo strerrmag
End If
Set DataGrid1.DataSource = rs
Exit Function
strerrmag:
mag = "Data can 't connect "
Call MsgBox(mag, vbOKCancel, "Error:Data connect ")
addFlag = False
End
End Function



错误提示的是  conn.Open  出现错误
实例错误-2147467259 (80004005)
[DBNETLIB] [ConnectionOpen (ParseConnectParams()).]无效的连接


求那位大仙给个解答


[解决办法]

VB code
'这样试试public conn as new adodb.connectionWith conn    If .State = adStateOpen Then .Close    .ConnectionString = "driver=SQL Server;server=计算机名或IP地址;uid=SA;pwd=SA的密码;database=数据库名"    .CommandTimeout = 0    .OpenEnd With
[解决办法]
本机要开启数据库的TCP/IP访问,否则无法通过IP访问。
127.0.0.1:1433改为127.0.0.1,1433

热点排行