开发者

Connection between windows service and sql database

I am trying to establishing a connection between a Windows service written in C# and a SQL Server Express database. But when connection.open is called I get this exception

System.data.sqlClient.sqlexception:

{"Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed."}

But the same code works fine when I run it as console application.Can someone please help me with this??

_connection = new SqlConnection("Data Source=.\\MSSQLSERVER1;AttachDbFilename=D:\\vinay\\project\\LightHistorian\\LH_DB.MDF‌​;Integrated Security=True;User Instance=True;");

i gave same credentials as local system.It works a times and doesnt at some other time.But when ever this exception happens,If i restart the machine it works.Wonder what the problem is??

开发者_如何学运维

I have used same connection for both windows service and console application


When you execute your console application, the EXE runs under your user credentials.
When you execute your service, which are user credentials? Is your service running under Locl Service Account? Or System? Or what?
Try to manually set the credentials your service must run with (in Windows services panel, check your service properties) and try to execute it with the same user/pwd you run your console app with.

UPDATE taken from here:
Using an User Instance on a local SQL Server Express instance
The User Instance functionality creates a new SQL Server instance on the fly during connect. This works only on a local SQL Server 2005 instance and only when connecting using windows authentication over local named pipes. The purpose is to be able to create a full rights SQL Server instance to a user with limited administrative rights on the computer.
I could think that your service credentials are not granted to create a new SQL server instance, so try to remove that part.
Anyway, set user credentials on service properties and see what happens.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜