Connect string of SQL Server for localhost in Entity Framework

c# connection-string entity-framework localhost sql-server

Question

I'm using SQL Server 2012 for my system, and using Entity Framework, Code first for access data base, my data base is local, but I can't connect using SERVER=localhost; in ConnectString

My App.config (Working)

  <connectionStrings>
    <add name="SystemContext" connectionString="Server=JOHN-PC\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
  </connectionStrings>

But, if I would install my system in an other computer, other data base, PC name is not JOHN-PC, so I need change it for a generic ConnectString
But when I change JOHN-PC\SQLEXPRESS for localhost, it is not work

What can I do for resolve this problem?

1
3
12/8/2013 2:26:01 PM

Accepted Answer

if you have database on other remote pc aswell you can use dot . instead of hardcoding machine name.

here . represents the localmachine.

Try This :

<connectionStrings>
    <add name="SystemContext" connectionString="Server=.\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
  </connectionStrings>

but if you want to run your machine as database server and want to every other pc to communicate with your PC for Database activities you can use IP address of your machine in your connection string.

12
12/8/2013 2:31:56 PM

Popular Answer

Try this:

<connectionStrings>
<add name="SystemContext" connectionString="Server=.\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>

The dot points to the local machine.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow