MSSQL 2014 Express

更新日2016-03-06 (日) 09:30:20

ユーザによるアクセス権制御(SQL Server 2014 Management Studio)

条件

以下のように設定するとADグループの営業部に属するメンバーがデータベースTESTを Read/Writeできる。

ロールメンバーシップpublicはすべてが属し消すことができない

権限1.png

Excel VBAからアクセス

ライブラリの追加

一番新しいActiveX Data Objects Library を追加

DAO1.png

VBA

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

ExcelにMSSQLからインポート

Excelメニューから:

その他のデータソース→SQLサーバ

次へ

次へ

完了


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS