条件
以下のように設定するとADグループの営業部に属するメンバーがデータベースTESTを Read/Writeできる。
ロールメンバーシップpublicはすべてが属し消すことができない
Private Sub CommandButton21_Click()
' Create a connection object.
Dim cnPubs As ADODB.Connection
Set cnPubs = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"
'Connect to the Pubs database on the local server.
' SOURCE=(ホストサーバ名)\(データベースサーバ名);INITIAL CATALOG=(データベース);"
'strConn = strConn & "DATA SOURCE=(local);INITIAL CATALOG=pubs;"
strConn = strConn & "DATA SOURCE=WIN2008R2SQL\SQLEXPRESS;INITIAL CATALOG=TEST;"
'Use an integrated login.
'Windows認証 "INTEGRATED SECURITY=sspi" こちらがよい
'OR "Trusted_Connection = Yes"でもWindows認証OKみたい
strConn = strConn & " INTEGRATED SECURITY=sspi;"
'Now open the connection.
cnPubs.Open strConn
'--------------------------
' Create a recordset object.
Dim rsPubs As ADODB.Recordset
Set rsPubs = New ADODB.Recordset
With rsPubs
' Assign the Connection object.
.ActiveConnection = cnPubs
' Extract the required records.(SQLの発行)
'.Open "SELECT * FROM Authors"
.Open "SELECT * FROM Table_1 Where ID=3"
' Copy the records into cell A1 on Sheet1.
Sheet2.Range("A1").CopyFromRecordset rsPubs
' Tidy up
.Close
End With
cnPubs.Close
Set rsPubs = Nothing
Set cnPubs = Nothing
End Sub
その他のデータソース→SQLサーバ
次へ
次へ
完了