Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OleDB connection string for SQL Server in a C# program

I have seen lots of answers to connect to MS Access via OleDB but there is not good answer for SQL Server. I try to connect to a SQL Server database via OleDB provider in my C# program.

This is the connection string I am providing.

Provider=SQLOLEDB;Data Source=<servername>;Initial Catalog=<dbname>;Integrated Security=SSPI

But it gives me error

‘Keyword not support ‘Provider’’

What I want to do here is connect database via OleDB in C# program.

like image 921
user2841795 Avatar asked Nov 30 '25 03:11

user2841795


1 Answers

This works as expected on my side. From the error message I strongly suspect that you are using the SqlConnection class instead of the OleDbConnection (Of course you need to use all the other classes provided by OleDb like OleDbCommand, OleDbDataReader etc...)

  string connStr = "Provider=SQLOLEDB;Data Source=<servername>;Initial Catalog=<dbname>;Integrated Security=SSPI";
  using(OleDbConnection cnn = new OleDbConnection(connStr))
  {
     ....
  }
like image 151
Steve Avatar answered Dec 02 '25 15:12

Steve



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!