oledb连接异常

时间:2011-12-29 08:50:40

标签: c# sql-server sql-server-2008 oledb

这是我的代码

string connectionString = @"Provider=SQLOLEDB;Data Source=Machine Name;Initial Catalog=MyTestDatabase;";
OleDbConnection conn = new OleDbConnection(connectionString);
DataTable result = new DataTable();
try
{
    conn.Open();
    OleDbCommand cmd = new OleDbCommand("get_holidays", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);
    adapter.Fill(result);
}
  

$ exception {“无效的授权规范”}在此期间抛出   conn.open()。

4 个答案:

答案 0 :(得分:2)

连接字符串格式:

Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

答案 1 :(得分:1)

Integrated Security=SSPI添加到您的连接字符串,尤其是在未指定用户名和密码时。在这种情况下,当前Windows account凭据用于身份验证。

Provider=SQLOLEDB;Data Source=ServerName;Integrated Security=SSPI;Initial Catalog=databaseName

答案 2 :(得分:0)

username

中没有passwordconnection string

答案 3 :(得分:0)

尝试此连接字符串

Provider=SQLOLEDB;Data Source=Machine Name;Initial Catalog=MyTestDatabase;Integrated Security=SSPI

如果无法在本地运行 - 那么您无法访问您的Sql Server