Option Compare Database
Public appAccess As Access.Application
Sub CallSQLDMOSQLServerLogin()
Dim srvname As String
Dim suid As String
Dim pwd As String
'' 设置 SQL Server 的登录参数
srvname = "(local)"
''suid = "sa"
''pwd = ""
'' 调用 SQL Server 登录过程
SQLDMOSQLServerLogin srvname, suid, pwd
End Sub
Sub SQLDMOSQLServerLogin(srvname As String, suid As String, pwd As String)
Dim srv1 As SQLDMO.SQLServer
'' 新建一个服务器实例
Set srv1 = New SQLDMO.SQLServer
'' 调用 SQL Server 登录连接方法
srv1.Connect srvname, suid, pwd
'' 断开连接
srv1.Disconnect
Set srv1 = Nothing
End Sub
Sub CallSQLDMOWindowsLogin()
Dim srvname As String
'' 设置 Windows 登录参数
srvname = "(local)"
SQLDMOWindowsLogin srvname
End Sub
Sub SQLDMOWindowsLogin(srvname As String)
Dim srv1 As SQLDMO.SQLServer
'' 新建一个服务器实例
Set srv1 = New SQLDMO.SQLServer
'' 在调用前,设置 LoginSecure 属性为 True
'' 使用服务名进行连接
srv1.LoginSecure = True
srv1.Connect srvname
'' 断开连接
srv1.Disconnect
Set srv1 = Nothing
End Sub
Sub CallChangeServerAuthenticationMode()
Dim constAuth As Byte
'' 设置 constAuth 参数为:
'' SQLDMOSecurity_Integrated 为 Windows Authentication 模式
'' SQLDMOSecurity_Mixed 为 Mixed Authentication 模式
'' 设置 constAuth 的默认值
constAuth = SQLDMOSecurity_Mixed
'' 调用改变 SQL Server 身份认证模式的方法
ChangeServerAuthenticationMode constAuth
End Sub
Sub ChangeServerAuthenticationMode(constAuth As Byte)
Dim srv1 As SQLDMO.SQLServer
'' 指定哪个服务器,默认为 Local (本地服务器)
srvname = "(local)"
'' 使用集成安全(Windows)方式新建一个 SQL Server 对象并进行连接
Set srv1 = New SQLDMO.SQLServer
srv1.LoginSecure = True
srv1.Connect srvname
'' 设置 SecurityMode 属性为 Windows 或混合身份验证模式
srv1.IntegratedSecurity.SecurityMode = constAuth
srv1.Disconnect
&nb