Connect string of SQL Server for localhost in Entity Framework
Solution 1
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
.
Solution 2
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 videos on Youtube
![Lai32290](https://i.stack.imgur.com/fS6G8.jpg?s=256&g=1)
Lai32290
Updated on September 15, 2022Comments
-
Lai32290 almost 2 years
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 ConnectStringMy
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 changeJOHN-PC\SQLEXPRESS
forlocalhost
, it is not workWhat can I do for resolve this problem?
-
Sudhakar Tillapudi over 10 years@Lai32290: you are welcome :), mark it as answer if it helps you.
-
Lai32290 over 10 yearsOkey, just wait more 3 minutes xD