oledb connection exception

孤者浪人 提交于 2019-12-03 00:12:16

问题


This is my code

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 {"Invalid authorization specification"} is thrown during conn.open().


回答1:


Connection string format:

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

or

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



回答2:


Add Integrated Security=SSPI to your connection string especially when username and password are not specified. In this case current Windows account credentials are used for authentication.

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



回答3:


Try this connection string

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

If will not work locally - then you have no access to your Sql Server




回答4:


no username and password in connection string



来源:https://stackoverflow.com/questions/8665673/oledb-connection-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!