SQL 使用 C# 的服务器
SQL Server with C#
我正在编写连接到 SQL 服务器的程序(IGOR-PC
- SQL 服务器 10.50.4044 - 实例 Igor-PC\Igor
)
代码是这样的:
SqlConnection myConnection = newSqlConnection("Server=.\Igor;Database=Prueba");
myConnection.Open();
但是我得到这个错误:
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)
not monitored System.Data.SqlClient.SqlException
谢谢!
试试这个
SqlConnection myConnection = new SqlConnection("Data Source=Igor;Initial Catalog=Prueba;Integrated Security=True");
编辑 2:
对于上图和TEST_DB
数据库,连接字符串应该写成
SqlConnection myConnection = new SqlConnection("Data Source=AJMOT-PC;User ID=sa;Password=thisismypassword;Initial Catalog=TEST_DB;Integrated Security=True");
如果您对 sql 服务器使用 Window 身份验证,则无需声明 User ID=sa;Password=thisismypassword
部分。
我正在编写连接到 SQL 服务器的程序(IGOR-PC
- SQL 服务器 10.50.4044 - 实例 Igor-PC\Igor
)
代码是这样的:
SqlConnection myConnection = newSqlConnection("Server=.\Igor;Database=Prueba");
myConnection.Open();
但是我得到这个错误:
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)
not monitored System.Data.SqlClient.SqlException
谢谢!
试试这个
SqlConnection myConnection = new SqlConnection("Data Source=Igor;Initial Catalog=Prueba;Integrated Security=True");
编辑 2:
对于上图和TEST_DB
数据库,连接字符串应该写成
SqlConnection myConnection = new SqlConnection("Data Source=AJMOT-PC;User ID=sa;Password=thisismypassword;Initial Catalog=TEST_DB;Integrated Security=True");
如果您对 sql 服务器使用 Window 身份验证,则无需声明 User ID=sa;Password=thisismypassword
部分。