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 或混合身份驗證