谢谢,但是我的机器就是可以连上服务器的呀,我也是客户端,只不过当初开发是在这个上面进行的。 错误是 数据源的问题,应为我在那台机器上编译的时候出现了错误,我看了一下是erp.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=db_zdtl;Data Source=datacenter"tm.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=tiaoma;Data Source=datacenter"出错了,我用的是模块,整个模块程序如下: Option Explicit Public erp As New ADODB.Connection Public tm As New ADODB.Connection Public z As String Public x As String Public y As String Sub Main() erp.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=db_zdtl;Data Source=datacenter"tm.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=tiaoma;Data Source=datacenter"Form1.ShowEnd Sub
dim cn as adodb.connect dim rscn as adodb.recordset dim connectstring as string connectstring="driver={SQLSERVER};server=serverip;uid=sa;pwd=;database=userdatabase" cn.open connectstring 你用这段试一下
'******这段程序可以检查出现的问题 Public adoCN As New ADODB.Connection '定义数据库的连接存放数据和代码 Public SqlCommand As New ADODB.Command '定义 SQL 命令Public Function OpenConnection() As String '打开数据库 On Error GoTo SQLConErr With adoCN .CursorLocation = adUseClient .Provider = "sqloledb" .Properties("Data Source").Value = cNtServerName .Properties("Initial Catalog").Value = cDatabaseName .Properties("User ID") = cSQLUserName .Properties("Password") = cSQLPassword .Properties("prompt") = adPromptNever .ConnectionTimeout = 15 .Open
If .State = adStateOpen Then adoDateTime.Open "select getdate()", adoCN, adOpenStatic, adLockOptimistic Else MsgBox "数据库连接失败,请找系统管理员进行检查 !", 16, cProgramName End End If End With
SqlCommand.ActiveConnection = adoCN SqlCommand.CommandType = adCmdText Exit Function SQLConErr: Select Case Err.Number Case -2147467259 MsgBox "找不到指定的SQL Server服务器或者数据库不存在,请重新设置!", vbExclamation F_SetSystem.Show 1 Case -2147217843 MsgBox "指定的SQL Server数据库用户不存在或口令错误,请重新设置!", vbExclamation F_SetSystem.Show 1 Case Else MsgBox "数据环境连接失败,请找系统管理员进行检查 !", 16, cProgramName End Select OpenConnection End Function
错误是 数据源的问题,应为我在那台机器上编译的时候出现了错误,我看了一下是erp.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=db_zdtl;Data Source=datacenter"tm.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=tiaoma;Data Source=datacenter"出错了,我用的是模块,整个模块程序如下:
Option Explicit
Public erp As New ADODB.Connection
Public tm As New ADODB.Connection
Public z As String
Public x As String
Public y As String Sub Main()
erp.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=db_zdtl;Data Source=datacenter"tm.Open "Provider=SQLOLEDB.1;Persist Security Info=true;User ID=sa;password=fjzhqm89uiaz;Initial Catalog=tiaoma;Data Source=datacenter"Form1.ShowEnd Sub
dim rscn as adodb.recordset
dim connectstring as string
connectstring="driver={SQLSERVER};server=serverip;uid=sa;pwd=;database=userdatabase"
cn.open connectstring
你用这段试一下
Public adoCN As New ADODB.Connection '定义数据库的连接存放数据和代码
Public SqlCommand As New ADODB.Command '定义 SQL 命令Public Function OpenConnection() As String '打开数据库
On Error GoTo SQLConErr
With adoCN
.CursorLocation = adUseClient
.Provider = "sqloledb"
.Properties("Data Source").Value = cNtServerName
.Properties("Initial Catalog").Value = cDatabaseName
.Properties("User ID") = cSQLUserName
.Properties("Password") = cSQLPassword
.Properties("prompt") = adPromptNever
.ConnectionTimeout = 15
.Open
If .State = adStateOpen Then
adoDateTime.Open "select getdate()", adoCN, adOpenStatic, adLockOptimistic
Else
MsgBox "数据库连接失败,请找系统管理员进行检查 !", 16, cProgramName
End
End If
End With
SqlCommand.ActiveConnection = adoCN
SqlCommand.CommandType = adCmdText
Exit Function
SQLConErr:
Select Case Err.Number
Case -2147467259
MsgBox "找不到指定的SQL Server服务器或者数据库不存在,请重新设置!", vbExclamation
F_SetSystem.Show 1
Case -2147217843
MsgBox "指定的SQL Server数据库用户不存在或口令错误,请重新设置!", vbExclamation
F_SetSystem.Show 1
Case Else
MsgBox "数据环境连接失败,请找系统管理员进行检查 !", 16, cProgramName
End Select
OpenConnection
End Function
用odbc 的意思 是不是在服务器上建立一个odbc 数据源连接我要的数据库呀,还是该程序??