简体   繁体   English

无法连接到附加的SQL数据库

[英]Cannot connect to attached SQL database

I'm using linq to sql with Microsoft SQL Server Database File (SqlClient) as a data source. 我正在使用linq to sql和Microsoft SQL Server数据库文件 (SqlClient)作为数据源。 The db file was created by Visual Studio 2010 while adding the connection (Database Explorer -> Add Connection). db文件是由Visual Studio 2010在添加连接(数据库资源管理器->添加连接)时创建的。 Using this method I was unable to create a db with SQL auth, so I'm using Windows Authentication. 使用这种方法,我无法使用SQL身份验证创建数据库,因此我在使用Windows身份验证。

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? 1)是否可以通过sql身份验证创建数据库文件? (I assume it is the root of the problem). (我认为这是问题的根源)。

2) Connection works fine on my computer under different acocunts. 2)在不同的环境下,我的计算机上的连接正常。 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. System.Data.SqlClient.SqlException(0x80131904):建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (提供者:SQL网络接口,错误:26-指定服务器/实例时出错)

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: EDIT2:我正在使用的连接字符串:

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

First of all, how was SQL Server installed? 首先,如何安装SQL Server? With Windows Authentication only or Mixed Mode authentication. 仅使用Windows身份验证或混合模式身份验证。 If it was just Windows Authentication that explains why you were unable to use SQL Server authentication. 如果只是Windows身份验证说明了为什么您无法使用SQL Server身份验证。 If mixed mode authentication is enabled then you need an account that has sysadmin or CREATE DATABASE privileges. 如果启用了混合模式身份验证,则您需要一个具有sysadmin或CREATE DATABASE特权的帐户。

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 您想要Microsoft SQL Server Express

It allows a file based connection. 它允许基于文件的连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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