0

I'm using entity Framework 6 DBContext , Database First.

I have created the Model using wizard form an existing SQL server database. Now on the app.config file , this connection string :

    <connectionStrings>

<add name="MyEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|    res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=My_PC;initial catalog=MyDatabase;integrated     security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

</connectionStrings>

This is working on a PC with SQL server installed. But if I try on a pc with SQL server Express , this is not working ( of course I have changed in the connection string the PC name. The database name is the same ).

What should I change in the above connection string in order to make it work on a SQL server express ?

My goal is to make this programmatically , so when my application is start , to test if is a SQL server or SQL server express environment and to make the changes on the app.config file .

Thank you !

alex
  • 694
  • 3
  • 15
  • 35
  • I believe the SQL Express installation configures a "named instance" of SQL Express. Take a look at [this answer](http://stackoverflow.com/a/3586284/76123). You will probably want to set the data source to `localhost\SQLExpress` or the equivalent. – Daniel Pratt Aug 12 '15 at 13:40
  • *this is not working* nah, I believe it's working. You claim it isn't working, yet you don't say how, nor do you have any exception details, etc in your question. I think that makes you a liar. Or, you can [edit], add those details, and make me the liar. Seriously, tho, @DanielPratt is probably correct. –  Aug 12 '15 at 13:41
  • @Will : If I use the same connection string as above , on a PC with sql server express installed , the application became busy (as if is searching for something ) and after stop responding. So I have no exception details to add on my question. – alex Aug 12 '15 at 13:50
  • Just hangs? Gotta time out eventually, which results in an error. Always. Tools such as Profiler can also help. Configure it to watch the express server, then watch as your app attempts to connect. –  Aug 12 '15 at 15:31
  • @Will : This is the error message : “A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) ” – alex Aug 12 '15 at 15:38
  • See? Trying to pull the wool over our eyes. Shame. That's a common error. Search for it in relation to sql server express. Usually you're not accessing the server properly (e.g., it's a named instance rather than the default, or vice versa), or the bloody thing isn't configured to listen on named pipes/tcp. There are many docs about troubleshooting this available for your reading pleasure. –  Aug 12 '15 at 15:41
  • @Wiil Sorry friend. Can you respond to my original question ? With this connection string on a SQl server it's working correctly. On a sql server express it's not working.The database name and sql server name are correct. And it's not shame to ask a question even if it's a easy stupid question. But you that may know the answer , may respond if you like. Thank you ! – alex Aug 12 '15 at 16:37

0 Answers0