3

I have web site running Visual Studio 2015 with local db,everything works great. But production server is not working.

connection string is

"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;". 

i tried connection string

"Data Source = (LocalDB)\V11.00; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;".

Full error is :

Server Error in '/' Application.

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: 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.

How can I solve the problem?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Çağrı Can Bozkurt
  • 653
  • 1
  • 10
  • 17
  • problem is that the database engine needs to be installed on the server since VS2015 installs all the related tools and drivers for you to perform development but the same engine are not installed on the server. you need to download the following: http://blogs.msdn.com/b/gaurav/archive/2013/12/21/deployment-of-sql-express-localdb-on-iis.aspx and also http://stackoverflow.com/questions/23320013/how-to-install-localdb-separately – Ahmed ilyas Nov 09 '15 at 09:08
  • **For Code Migrations** (`update-database` et al) [see this answer](https://stackoverflow.com/a/31266905/3258851). – Marc.2377 Jul 31 '18 at 21:20

2 Answers2

1

Since you changed environments, for e.g. local laptop to prod server

For production, check and update your data directory.

"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;".

to debug Hard code the directory path, if it works you can set you env variable for =|DataDirectory|\SeedDb.mdf Then check server/roles for the dir under security (right click folder)

Transformer
  • 6,963
  • 2
  • 26
  • 52
-2

Your init string should point to the instance name of your production SQL server.

data source=SQLSERVER\INSTANCE;initial catalog=databaseName

SQL Server can be installed as a default instance. In that case instance name should be omitted.