views:

1067

answers:

3

Hi There,

I have a very funny problem on my application, I get an error as follow: System.ArgumentException: An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'.

However, when I tried to speicify the provider on my connection as Provider=SQLOLEDB.1 or Provider=SQLOLEDB, then I get another error saying invalid keyword 'Provider'.

But one thing I noticed, the computer that I am targeting to had 2 different database system, will that cause this error?

Any idea how to solve this problem?

Regards

A: 

Looks like your missing some bits of the connection string - try these

General Connection String:

strConnect = _T("Provider=sqloledb;Data Source=MyServerName;" "Initial Catalog=MyDatabaseName;" "User Id=MyUsername;Password=MyPassword;");

Named Instance Connection String:

strConnect = _T("Provider=sqloledb;Data Source=MyServerName\MyInstanceName;" "Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");

Trusted Security:

strConnect = _T("Provider=sqloledb;Data Source=MyServerName;" "Initial Catalog=MyDatabaseName;" "Integrated Security=SSPI;");

From here http://www.codeproject.com/KB/database/connectionstrings.aspx#OLE DB SqlServer

But when I add Provider on my connectionstring, I got another error saying invalid keyword provider.
PlayKid
A: 

Assuming that you are using ADO.NET, if you want to use distinct database systems, then you need to correct the DbConnection too, not only the connection string.

Note that you can't use an SqlConnection for OLEDB, you need to use System.Data.OleDb.OleDbConnection instead.

I have published an open-source application that does this sort of trick, you can have a look at the code at http://lokad.svn.sourceforge.net/viewvc/lokad/Platform/Trunk/SafetyStockCalc/Source/Lokad.SafetyStock.InventoryAdapter/XmlAdapter/XmlInventoryAdapter.cs?view=markup

Joannes Vermorel
I was using SqlConnection for that, so I am using the correct DbConnection as I am not using a general connection for my application.
PlayKid
You can't use SqlConnection for OLEDB, check my last edit on my answer.
Joannes Vermorel
A: 

I am getting the same problem, I am using a connection string in my web.config file that doesnt have an attribute called provider, but instead an outside attribute called providerName , now even wen i set this providername to system.data.oledb and i try to use it wen creating an oledbconnection object it says "error provider not specified" etc

can anyone tel me why im in this circle?

if i use provider i get provider not an attribute error (in the webconfig) if i dont use provider i get provider missing...

Mohi