0

I cannot get my web app to connect to the database when running the app. I can connect in the SQL Server object explorer and I took the connection string from the connections properties

Here is my connection string :

<add name="Quotes.DAL.QuotesConnection" 
     connectionString="Data Source=(localdb)\v11.0;Initial Catalog=TestDB;Integrated Security=False;User ID=sa;Password=***;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False" 
     providerName="System.Data.SqlClient" />

I can connect as SA and I can create the database that it points to in Management Studio. When my app tries to connect via Entity Framework I get the following error :

System.Data.SqlClient.SqlException (0x80131904): Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,

I'm running Windows 7 as a home dev machine so there is no Active Directory.

Can anybody explain why this might happen?

I have found that this is probably because I have Entity Framework in another assembly. I created a new web application and its connection string works. When it try the same connection string in my DAL it fails with this same error!

Thanks

4
  • Do you have a server certificate? You have set this up with TrustServerCertificate = False. If you have no verifiable certificate the connection attempt will raise an exception. I suspect you probably should just remove the TrustServerCertificate section in the connection string. Commented Mar 19, 2015 at 20:37
  • Here is a link that explains that setting. msdn.microsoft.com/en-us/library/ms254500%28v=vs.110%29.aspx Commented Mar 19, 2015 at 20:38
  • thanks. i tried to remove this. it does not make a difference. Commented Mar 19, 2015 at 20:54
  • Have you tried looking at connectionstrings.com? Commented Mar 19, 2015 at 20:55

1 Answer 1

1

It may be because of setting Integrated Security=False, I have never set it to false. I normally use just the bare minimum Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword; when setting up my connection strings with sql authentication, only adding things as I need them.

The other issue I see is using SA to connect to the database. This breaks almost every best practice in the book and I would recommend creating an app specific password for when you roll out the program. The reason being is the GOD ACCESS account for the server will have its password in plain text in the app.config file. Just something to keep in mind.

EDIT: After some comment discussion the connection string was in the wrong config file.

Sign up to request clarification or add additional context in comments.

6 Comments

hi i am using this connection string to test as i get this error when connecting using windows authentication. I would not normally use sa i just want to find a solution. i have found that this is probably because i have entity framework in another assembly. i created a new web application and its connection string works. when it try the same connection string in my DAL it fails with this same error!
@Paul Are you putting the connection string in the app.config that is created in the DAL.dll project?
yes i put the connection string in the app config of the DAL assembly. i have no connection strings in the UI project. could this be the problem?
Yes you will need to put the connection string into the UI project. This is confusing sometimes but true.
@Paul Yes that is the problem. All the EF app config information needs to go in the web.config (or app.config of the executable). Otherwise it does not get picked up. You also need to add the EF dll's (nuget package) to the web app (or exe).
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.