tags:

views:

1473

answers:

2

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

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

The error indicated the login failed for my user name. My user name and password were correct, but the fix was to copy my connection string to the correct location. I've learned the issue from another site and thought I would make a note here.

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

+2  A: 

The LINQ designer ads the connection string to the app.config of the class library, but the web site needed to see it in the web.config of the web project. Once copied across all was well.

Adrian
+1  A: 

you can pass in a connection or connection string to the data context as well.

Darren Kopp
Hi Darren, I'm not sure I understand what you mean. I can see how storing in the web.config makes it work I understand you can reference a custom connection string when you instantiate the data context, but would that involve storing the connection coded elsewhere (other than web / app config?)
Adrian
Yes, i'm talking about having it stored someplace else. Like at my company, we have 1 codebase shared between multiple customers on multiple databases, so we can't store in web.config, so we have a factory that gets their config and creates the connection string.
Darren Kopp