.net - Can't connect to SQL LocalDB from Windows Service, WPF app & SSMS work fine? -


having trouble system i'm developing. layout far question concerned wix built msi installer installs sql localdb 2012, wpf app, , windows service. both windows service , wpf app communicate same database, app driven user interaction , service on timer.

everything gets installed cleanly, db instance gets installed in mixed mode , database initializer creates new login , user instance , db, , in ssms both appear configured correctly. can log in , query tables fine using new login. here code used create login:

if not exists  (select loginname   master.dbo.syslogins name = 'bp_servicelogin')   begin     create login[bp_servicelogin] password = 'pw';    create user[bpuser] login[bp_servicelogin] default_schema = dbo;         use databasename;     exec sp_addrolemember 'db_owner', 'bpuser'   end 

so reiterate; login works fine in ssms , allows me log in , access database created wpf app's initializer.

however, not able login database windows service. making sure use new login in connection string , set there. how know this? because when copy connection string wpf app , use instead of windows auth, works!?!

the service fails message:

"system.data.entity.core.entityexception: underlying provider failed on open. in entityframework:file: method:open line:0 column:0   system.data.sqlclient.sqlexception: login failed user 'bp_servicelogin'. in .net sqlclient data" 

here connection string i'm using:

<add name="connstringname" providername="system.data.sqlclient" connectionstring="data source=(localdb)\v11.0;initial catalog=dbname;user id=bp_servicelogin;password=pw;multipleactiveresultsets=true;application name=servicename" /> 

it seems there barrier keeping connection windows service connecting while others have no such problem. localdb installation fresh , other db , login/user created, has nothing done oob state.

can help?

i'm not professional in windows services.

i think fault in windows service have written. session 0 isolation may have run windows service in specified user account.
helpful if can give user account windows service runs. in default service runs in different user account called system account. account may not have permission access database. might cause problem.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -