how to access localDB from Windows Service

后端 未结 3 1360
走了就别回头了
走了就别回头了 2020-12-19 11:21

I need to use data base locally. I have created database in (LocalDB)\\v11.0 Server with Visual Studio 2012. Everything is ok when connecting from e.g. console application.

3条回答
  •  忘掉有多难
    2020-12-19 12:19

    Probably your connection string is using the current Windows User account (the account that runs the service could be the one seen on the error) to connect to the database (and that user account does not have access). What I would do is that I would change the database to allow "mixed authentication" (this means SQL users and Windows users too) and then I would create a new user, assign that user the required permissions to work with your app and then use that userName and password in the connection string from your windows service. You could also leave the DB as it is and add user "System" from Windows and then assign the required permissions to it. You can just add "dbo" profile to a user to make it work fast (but check security later before releasing your product).

提交回复
热议问题