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().
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;
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
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
Brijesh Mishra
no username
and password
in connection string
来源:https://stackoverflow.com/questions/8665673/oledb-connection-exception