Link to home
Start Free TrialLog in
Avatar of Moti Mashiah
Moti MashiahFlag for Canada

asked on

asp.net mvc

Hi Guys,

I have some issue with my default connection through web.config.

I have configured my default connection to connect my local database server and I'm getting error "Unable to connect to SQL Server database".
I have checked my server name 10 times and my database name as well, and I found all is good. also I tested from server explorer in visual studio and it works fine and connecting to the SQL server:

Here is how I'm trying to connect through web config and fail anytime:

<add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=Codeexample;Persist Security Info=True;User ID=sa;Password=*******;multipleactiveresultsets=True;" providerName="System.Data.SqlClient" />

Open in new window



Thanks ,
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

bring up sql config and enable tcpip and restart the sql server
Avatar of Moti Mashiah

ASKER

The SQL is on local machine and I can connect from any other applications.

Anyway I will try your suggestion and let you know.

Thanks ,
I just checked and tcp\ip is enable.
As I said before I can connect to SQL from anywhere else.


Thanks,
After I checked again I can prove that my SQL server is working fine. I telnet to port 1433 and also connected from different solution I have and all work fine.

The issue is in my web.config in connection string I'm pretty sure.

Actually, I'm really confuse as I have two connection string in same web.config and one of them work.
 look at the config connectionstring. (the second one "CodeexampleEntities" is connecting with no issue ) the first connection is for user authentication and this is fail.

 <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=Codeexample;Persist Security Info=True;User ID=sa;Password=*******;multipleactiveresultsets=True;" providerName="System.Data.SqlClient" />
  <add name="CodeexampleEntities" connectionString="metadata=res://*/Code.csdl|res://*/Code.ssdl|res://*/Code.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=Codeexample;persist security info=True;user id=sa;password=******;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Moti Mashiah
Moti Mashiah
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
solved