Public adoCN As New ADODB.Connection '定义数据库的连接存放数据代码
Public SqlCommand As New ADODB.Command '定义 SQL 命令
Dim adoDateTime As New ADODB.Recordset '获取 NT-SERVER 时间
'***********************************************************************
'* 功能:与 SQL SERVER 数据库建立连接并取出服务器时间
'***********************************************************************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
cServerDate = Format(adoDateTime(0), "yyyy-mm-dd")
cServertime = Mid(adoDateTime(0), 10)
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
Public SqlCommand As New ADODB.Command '定义 SQL 命令
Dim adoDateTime As New ADODB.Recordset '获取 NT-SERVER 时间
'***********************************************************************
'* 功能:与 SQL SERVER 数据库建立连接并取出服务器时间
'***********************************************************************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
cServerDate = Format(adoDateTime(0), "yyyy-mm-dd")
cServertime = Mid(adoDateTime(0), 10)
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
解决方案 »
- 怎样将几个数组中的元素去出全都包含的?
- 这个代码每句的注释 请大家帮忙
- 如何将某个目录下的某一类文件全部查询出来?
- 怎样调用 SQL SERVER 存储过程
- 关于打印问题
- 请专家帮忙呀!为什么会报“Run-time error '3706'"错误?
- !!!!!!!!!!!!!!!!紧急。谢谢
- 求VB高人一名,求师或有偿写个东西!
- 急!急!急!请教TreeView的问题?
- <<<<<请问怎么使DTpicker控件在运行中显示当前日期,我的总是显示设计时的日期,不随系统时钟自动变化!还有怎么通过一个窗体的CommandButton控件调用另一个窗体出来进行操作?多谢大家了!!!
- 如何在VB下调用FLASH动画
- 如何自动关闭一个msgbox?
复制例子代码
2、添加数据环境,设置连接,再到属性框中复制连搠字串替换代码中原有的连接字串
3、删除数据环境