I have a solution with three projects: a web application, the data access layer to create the code first database and a windows service which I (would like to) use for syncing some data in the database. I have also referenced the data layer in both of the other projects. I am using the same connection string in the web application config and the service config. Everything works fine for the web application, but when I access the data context all the tables are empty (Enumeration yielded no results). I get no errors. So my question would be that am I missing something obvious?
<add name="DataContext" connectionString="Data Source=(localdb)\MSSQLLocalDB; Database=Purple Moose; Integrated Security=True; User Id=purplemoose; Password=password; MultipleActiveResultSets=True;" providerName="System.Data.SqlClient" />
Your connection string uses the current windows user for login to your database. You specified both, integrated security (aka windows user) and username/password.
In that case:
Windows authentication takes precedence over SQL Server logins. If you specify both Integrated Security=true as well as a user name and password, the user name and password will be ignored and Windows authentication will be used.
So you will always lo into your database with the current windows user and that is probably Local System or something similar for your service. Either way, as you want username/password authentication, remove Integrated Security=true or set it to false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With