我得到的错误是"错误关键字不受支持:'提供商名称'"并指向连接字符串!我在下面的代码中留下了错误顶部的注释。任何帮助将不胜感激。
连接到服务器数据库时似乎是一个非常常见的错误。我尝试使用提供程序OleDb.OleDbConnection,但这也给了我一个不同的例外,即提供程序未在本地计算机上注册!
static void Main(string[] args)
{
string connectionString = "Data Source = Datasource; Initial Catalog = name; User Id = user; Password = pass; providerName=System.Data.SqlClient;";
string queryString = "SELECT ID from SERVICE WHERE ServiceNum1 = 1";
int paramValue = 5;
//Error Keyword not supported: 'providername'
using (SqlConnection connection = new SqlConnection(connectionString))
{
// Create the Command and Parameter objects.
SqlCommand command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("@ID", paramValue);
//try
//{
connection.Open();
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("\t{0}",
reader[0]);
}
reader.Close();
//}
//catch (Exception ex)
//{
// Console.WriteLine(ex.Message);
//}
Console.ReadLine();
}
}