Login failed for user "username" - System.Data.SqlClient.SqlException with LINQ in an external project / class library

This may seem obvious, but I had this error when trying to use LINQ to SQL with my business logic in a separate class library project.

I created DBML in a class library with all my business logic and custom controls in this project. I referenced the class library from my web project and tried to use it directly from the web project.

The error indicated that the login failed for my username. My username and password were correct, but the fix was to copy the connection string to the right place. I found out about the problem from another site and thought I'd take a note here.

Error: Login failed for user 'username' System.Data.SqlClient.SqlException

+3
linq-to-sql
Sep 18 '08 at 22:18
source share
2 answers

The LINQ designer advertises the connection string in the app.config class library, but the website should see it in the web.config web project. After copying, everything was fine.

+3
Sep 18 '08 at 22:19
source share

You can also pass a connection string or connections to the data context.

+2
Sep 18 '08 at 22:23
source share



All Articles