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 usingSERVER=localhost; connected string

My App.config (Working)

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

However, I would need to modify it to a generic name if I were to install my system on another computer with a different data base.ConnectString
However, if I alterJOHN-PC\SQLEXPRESS for localhost it doesn't work

What can I do to fix this issue?

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

Accepted Answer

If there isdatabase Additionally, you can utilizedot. as opposed to hardcoding the machine name.

here . displays thelocalmachine .

Do This:

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

however, if you want to use your computer as a database server and allow all other computers to interface with it for database-related tasks, you can useIP address using your device in yourconnection string .

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

Popular Answer

ZZZ_tmp


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