我看到其他人已经解答了这个错误,但是我似乎无法让它起作用。我正在尝试在本地连接到SQL Server数据库项目。
当执行以下操作时,我会在Open()上抛出此错误:
SqlConnection conn = null;
conn = new SqlConnection(connection)
conn.Open()
其中 connection 是从我的 webconfig 文件中传递的连接字符串。我在网上找到了一些示例,尝试使用了以下三个连接字符串,但每次都收到相同的错误:
<add name="TICKETING_CONNECTION" connectionString="Server=(local); DataBase=Ticketing_DB; Integrated Security=SSPI"/>
<add name="CONN"
connectionString="Data Source=localhost; Integrated Security=SSPI;Initial Catalog=Ticketing_DB"
providerName="System.Data.SqlClient" />
<add name="CONN2"
connectionString="Data Source=(local);Initial Catalog=Ticketing_DB;"
providerName="System.Data.SqlClient"
/>
问题可能来自于数据库在我的计算机上的路径吗?我已经尝试复制c:\路径,但没有成功。我在网上看到一些示例使用了.mdf文件,但我的项目中也没有这个文件。
这是我第一次尝试连接到数据库项目,所以任何帮助或建议将不胜感激。
localhost\sqlexpress
。 - squillman