0
votes

I am using C# to connect to my database with sqlconnection. But now I want to connect using OledbConnection. I'm using this instruction:

 _dbSchemaInfo.Connection.ConnectionString = ViewModelLocator.Connection.ConnectionString;

and I have this Error:

Un fournisseur OLE DB n'était pas spécifié dans ConnectionString. Par exemple, 'Provider=SQLOLEDB;'.

My ConnectionString:

Data Source=MOHAMEDSADEK-PC\MSSQLSERVER12;Initial Catalog=TEST_LAUNCHER;Integrated Security=SSPI;Persist Security Info=False

My question is "How Can I convert sqlconnection to OledbConnection ?

1
The error message says your connection string is wrong. Without your connection string we definitely can't tell you why it is wrong. - Chris
My connection work in other methode in the same programme. I thing I found it. I have to declare my connection as a DbConnection and instantiate it as either a OleDbConnection or a SqlConnection later. - xtensa1408
My problem always exist !! - xtensa1408
Without the relevant code we can't help. The syntax of OLEDB and SQL connection strings is different. You can't use a SQL Server connection string with an OleDBConnection class. Anyway, if you are using the abstract DbConnection class correctly, you shouldn't care whether an OLEDB or a SQL connection is created. Where is the code that creates the connection and why do you want to open an OleDbConnection? - Panagiotis Kanavos

1 Answers

0
votes

According to your error message and this link, you need to set a Provider in your ConnectionString.

e.g. :

Provider=sqloledb;Data Source=MOHAMEDSADEK-PC\MSSQLSERVER12;Initial Catalog=TEST_LAUNCHER;Integrated Security=SSPI;Persist Security Info=False

See more about connection providers with this links :

Provider Property (ADO) : https://msdn.microsoft.com/en-us/library/windows/desktop/ms675096(v=vs.85).aspx

I hope it will help