-1

I have been trying to make my c# database application run everywhere but when using the following connection string

 <add name="DBCS"
   connectionString="Data Source=(LocalDB)\v13;AttachDbFilename=|DataDirectory|\ServiceCardRecorderDatabase.mdf;Integrated Security=True;database=ServiceCardRecorderDatabase"
   providerName="System.Data.SqlClient" />

and when I try to insert data to the table I get an exception saying System.Data.SqlClient.SqlException: '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: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist. thrown from Visual Studio:

image of error

Aman G
  • 61
  • 10
  • You didn't include your connection string. – William Xifaras Mar 30 '17 at 15:53
  • Please enter the text of the error into your question, rather than including it as a picture. Pictures are hard to search, they require an extra step to view, extra bandwidth etc. – mason Mar 30 '17 at 15:54
  • Please include some code so we can see what you have tried. – Rafael Mar 30 '17 at 15:54
  • I don't believe any of this. I see no code demonstrating how you insert data into a table, I see no connection string, and I certainly don't see an exception. I do see what appears to be a link to an image, but for all I know that's some illegal stuff right there. You need to [edit] and fix this question (code, connection string, full exception details) if you want an answer. –  Mar 30 '17 at 15:54
  • @WilliamXifaras Yes, he did. He just didn't format it in a way that would display when the Markdown was parsed. I've corrected that. – mason Mar 30 '17 at 15:55
  • I have edited my question...see it again – Aman G Mar 30 '17 at 15:57
  • Okay, so now you've got your configuration and the error somewhat visible in your question (it'd still be better to include the text rather than an image). Now for the error itself: it says that LocalDB instance isn't configured. What steps have you done to ensure that it's configured? – mason Mar 30 '17 at 15:59
  • I have created the local database from server explorer what do not understand in the connection string is |DataDirectory| can you explain how to use it. – Aman G Mar 30 '17 at 16:02
  • @AmanG DataDictionary is a substitution string that indicates the path to the database. https://stackoverflow.com/questions/1409358/ado-net-datadirectory-where-is-this-documented – William Xifaras Mar 30 '17 at 16:10

2 Answers2

0

Try modifying the following subsection in entity framework section in your web.config to

<parameters>
        <parameter value="correctdbversion" />
</parameters>

Where correctdbversion can be either of the following, mssqllocaldb, v11.0, v12.0

0

Thanks all for your effort, finally I found the problem solved by using this connection string below.

<add name="DBCS" connectionString="Data Source=(LocalDB)\mssqllocaldb;AttachDbFilename=|DataDirectory|\App_Data\ServiceCardRecorderDatabase.mdf;Integrated Security=True"
       providerName="System.Data.SqlClient" />

I just added the folder name in which I put the mdf file in the project folder after |DataDirectory| and its runs as expected.

Aman G
  • 61
  • 10