[英]How to connect to SQL Server using oledbConnection
我正在尝试使用OledbConnection连接到SQL Server,但显示错误
服务器不存在或访问被拒绝
我的代码是
using (OleDbConnection conn = new OleDbConnection(ConnectionString))
{
try
{
// test the connection with an open attempt
conn.Open();
this.Dispose();
}
catch (Exception ex)
{
// inform the user if the connection was not saved
MessageBox.Show(ex.Message, "Connection Test");
}
}
这是MSSQL Server可用连接字符串的列表。 如果使用System.Date.SqlClient命名空间,那就更好了。
Using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open()
// do something here
}
catch (SqlException ex)
{
}
finally
{
connection.Close()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.