简体   繁体   中英

Cannot connect to attached SQL database

I'm using linq to sql with Microsoft SQL Server Database File (SqlClient) as a data source. The db file was created by Visual Studio 2010 while adding the connection (Database Explorer -> Add Connection). Using this method I was unable to create a db with SQL auth, so I'm using Windows Authentication.

EDIT: Note that it's not a connection to a database, it's a connection to a database file.

1) Is it possible to create a database file with sql authentication? (I assume it is the root of the problem).

2) Connection works fine on my computer under different acocunts. However, running the release on other machine results in an exception being thrown.

Exception details:

System.Data.SqlClient.SqlException (0x80131904): 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)

I've tried to set the db path manually, but I guess it's not the issue.

What am I doing wrong?

EDIT2: the connection string I'm using:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\OperatorResults.mdf;Integrated Security=True;Connect Timeout=10;User Instance=True"

First of all, how was SQL Server installed? With Windows Authentication only or Mixed Mode authentication. If it was just Windows Authentication that explains why you were unable to use SQL Server authentication. If mixed mode authentication is enabled then you need an account that has sysadmin or CREATE DATABASE privileges.

As for your second question, did you modify connection string to match the connection configuration of another machine? If not, try doing that. From the exception above it seems that your connection string is connecting to a wrong server or the server instance is not running.

You want Microsoft SQL Server Express

It allows a file based connection.

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