3

I have the connection string:

  <connectionStrings>
    <add name="SolrLocal" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLExpress;Initial Catalog=SpeedOfLightRailDB;Integrated Security=true" />
  </connectionStrings>

But I'm getting the error:

"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)"

This is my first time playing with SQL Server Express so I might be missing something obvious....

Can anyone at least confirm that this is what the connection string should look like for Entity Framework -> SQL Sever Express? I've been changing it around trying to get it to work.

RJB
  • 2,063
  • 5
  • 29
  • 34
  • 1
    Please make sure if MS SQL Server service is running. To do that just go to Control Panel > Administrative Tools > Services and try to find 'sql...' service. make sure if have status "Running". Another tip is use you network machine's name instead of dot for data source field, example:"Hardworker\sqlexpress;..." – Anton Norko Feb 28 '16 at 03:20
  • Can you connect to .\SQLExpress on that box via SSMS? – Chaim Eliyah Feb 28 '16 at 03:39
  • Is your web server on the same server as the SQL Server? – Nick.Mc Feb 28 '16 at 23:18
  • Connecting with SSMS is a no go – RJB Mar 10 '16 at 02:35

3 Answers3

2
  1. Check your windows services and make sure that the sql server express windows service is running. You can get to services by running services.msc from the RUN command bar (windows key + R). If it is not running then start it.
  2. Do you have Sql Server Management Tools installed? If so you can try to connect using those tools. If you cant connect to your sql server express instance from there, most likely you will not be able to connect from code either. If you do not have this installed no worries, you can still test it with the next step.
  3. If you need help building the connection string this next one is a great way to do it. Create a text file on your desktop. Rename the extension from .txt to .udl. Open the file and you will get a Data Link Properties screen, start with the 1st tab (it defaults to tab 2) and then fill in the second one also. Once you test your connection here and it works you can open the file using NotePad or rename the extension back to .txt and open it in NotePad. The connection string will be on the 2nd line in the text file. Just copy and paste it to your .config file.

If none of this works then report back with what you have found and any errors you are getting.

Igor
  • 60,821
  • 10
  • 100
  • 175
  • Under services, there's `SQL Server (SQLEXPRESS)` and `SQL Server Agent (SQLEXPRESS)`, but trying to Start the former gives me an error: "Windows could not start the SQL Server (SQLEXPRESS) on Local Computer. For more info, review the System Event Log...." – RJB Mar 10 '16 at 02:25
  • Far as I can tell, from `eventvwr.exe`, the error it's referring to might be: "Initializing the FallBack certificate failed", but there's a few other SQLEXPRESS errors in the log too – RJB Mar 10 '16 at 02:26
  • @RJB - I found [SQL Server not starting - FallBack certificate initialization failed](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/56f14665-3f00-41ff-b002-bb5e86b3f219/sql-server-not-starting-fallback-certificate-initialization-failed?forum=sqlsecurity) on an MSDN forum. Can you see if this answer helps resolve the service not starting? – Igor Mar 10 '16 at 13:30
1

You are using .\SQLExpress and I think your local servername is different. What you can do is open your SQL Server and then while connecting see the server name used. You must enter the same name in your web config. Refer the below image which shows the server name while connecting to the SQL server, In my case I need to replace .\SQLExpress with RAJSHEKAR-PC\SQLEXPRESS

enter image description here

Rajshekar Reddy
  • 18,647
  • 3
  • 40
  • 59
  • 1
    `.` and `localhost` both mean 'connect to the local host'. It is not necessary to put a host name in. – Nick.Mc Feb 28 '16 at 13:13
  • It depends on how the installation was done. During installation we can set it to . or localhost or A host name, It will never connect by just saying . and localhost only because of the fact that it's installed in your local machine. It is installation dependent – Rajshekar Reddy Feb 28 '16 at 13:37
  • nonsense. if you go into `cmd` and type `ping localhost` you'll find that it pings your local pc. They all resolve to the same thing. – Nick.Mc Feb 28 '16 at 13:40
  • But yes it certainly is installation dependent. If they changed the default instance name from `SQLExpress` to `myinstance` then the server name would have to be `localhost\myinsance` – Nick.Mc Feb 28 '16 at 13:44
  • I checked your above comments and yes you were right. Thanks for the info mate. But I did post this solution because this is not the case when we open connection from a web application. The host names doesn't resolve when using `.` or `localhost` all the time. – Rajshekar Reddy Feb 28 '16 at 14:29
  • 1
    Possibly because your web server is on a different server. So in that case you need to use the fully qualified name. So you could be completely correct if the OP's web server is on a different server but he hasn't given us any clues. – Nick.Mc Feb 28 '16 at 23:17
1

Try this:

<connectionStrings>
    <add name="SolrLocal"
        providerName="System.Data.SqlClient"
        connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SpeedOfLightRailDB;Integrated Security=True;MultipleActiveResultSets=True"/>
</connectionStrings>

Also check if .\SQLEXPRESS is accessible from SQL Server Management Studio, and if SQL Server is configured to allow remote connections in SQL Server Configuration Manager.

enter image description here

It can be launched from cmd like this: C:\Windows\SysWOW64\mmc.exe /32 C:\Windows\SysWOW64\SQLServerManager12.msc

gofr1
  • 15,741
  • 11
  • 42
  • 52