简体   繁体   中英

Using LocalDB with Visual Studio

I have Visual Studio 2015 installed and I created a sample application from some Microsoft tutorial.

This is the connection string I got in web.config :

<add name="DefaultConnection" 
     connectionString="Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-GeekQuiz-20160203041206.mdf;Initial Catalog=aspnet-GeekQuiz-20160203041206;Integrated Security=True" 
     providerName="System.Data.SqlClient" />

But it doesn't work, this is the error I got:

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.

Should I install SQL Server Express separately or I got it along with Visual Studio?

I usually use the next trick to set the correct connectionString in the Web.config:

In Visual Studio, go to the “SQL Server Object Explorer” label, right-click on the Database you wish to use and click on “Properties”. Then get the string in the “Connection string” field.

Try giving permissions to SQL server on the directory of App_Data. Go to properties->Security->Edit->Add and add the sql server instance name. It is usually NT Service\\MSSQL$InstanceName. You can find instance name from sql server configuration manager-> Under SQL Server Network Configuration. If this doesn't help, then try adding PC Name\\Users. It should work after that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM