2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Azure ServiceFabric - エミュレーターからLocalDBへの接続

Last updated at Posted at 2017-05-25

LocalDBは外部からの接続に制限がある。
Azure Service FabricのエミュレーターからLocalDBへ接続する場合、外部接続
扱いとなってしまう。

LocalDBに共有名を設定し、"NETWORK SERVICE"アカウントを追加し、db_ownerのロールにマッピングすると、Service Fabricのエミュレーターから共有名でのアクセスができるようになる。

コマンドプロンプトから下記のコマンドを実行。
[[databasename]]のところは環境に合わせて変更(3か所)

sqllocaldb create MSSQLLocalDB
sqllocaldb start MSSQLLocalDB
sqllocaldb share mssqllocaldb sharedlocal
sqllocaldb stop MSSQLLocalDB
sqllocaldb start MSSQLLocalDB

"c:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE" -S "(localdb)\.\sharedlocal" -d "[[databasename]]" -Q"create login [nt authority\network service] FROM windows with DEFAULT_DATABASE=[[databasename]];use [[databasename]];exec sp_addrolemember 'db_owner', 'nt authority\network service';"

App.configの接続文字列を下記のように設定
[[DbContextName]]、[[databasename]]は環境に合わせて変更

<add name="[[DbContextName]]" connectionString="data source=(localdb)\.\sharedlocal;initial catalog=[[databasename]];integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />

参考
stackoverflow - Using LocalDB with Service Fabric

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?