odbc connection to access- error
Hi,
Im trying out a ODBC Connection to Access.
My connection string is as following
Code:
strCn = ("Data Source=cntCal; Initial Catalog=Calendar;");
I get the following error
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I rechecked my datasource name and it is indeed cntCal.
What could be the problem
:o
Re: odbc connection to access- error
For access you don't need an initial catalog. I would suggest using DSN less connection string. Take a look at http://www.connectionstrings.com/?carrier=access
Re: odbc connection to access- error
Hi,
well earlier in VB 6, it was possible to connect to a access datatbase via ODBC. Has this facility been removed in c#. I tried the above line
Code:
strCn = ("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\\Calendar.mdb;Uid=;Pwd=;");
thats too throws the same error.
Well. when i use OLEDB connection then its fine.
I just thought of practising a ODBC connection similarly.
Re: odbc connection to access- error
No the functionality has not been removed. The way you use Databases in .NET has been changed though. For DSN Connections you will have to use classes in System.Data.ODBC, whereas for OLEDB you don't need a DSN, you can directly connect to the MDB file using the provider and path of the file.
You should be looking at System.Data namespace and check what are the different ways of connecting databases with .NET.
System.Data.ODBC -- For DSN connection
System.Data.OleDB -- For conenctions where you know the providers
System.Data.SQLClient -- For SQL Server
And there are third party providers for Oracle and MySQL too.
Did you go through the link that I had posted. if you would have gone through that link, you would gotten your answer.
I would also suggest grabbing a tutorial on ADO.NET and do some reading.
Re: odbc connection to access- error
Hi,
thanks for replying...I would go thru these
Re: odbc connection to access- error
Quote:
Originally Posted by sunshine123
Hi,
thanks for replying...I would go thru these
And the conenctionstring that you have pasted works perfectly with the ODBCConnection object.
Is there any other error that you are getting. It will also be helpful if you tell us what is the exact error message that you are getting and the exact code that you are using.
Re: odbc connection to access- error
Thanks... here it is...I was just practising...Imquite new to c#. I used oledb connection. So thought of trying with odbc.
Code:
class ConnDB
{
OdbcConnection conn;
string strSql;
string strCn;
OdbcDataAdapter adapter;
DataTable dt;
public ConnDB()
{
strCn = ("Data Source=cntcal; Initial Catalog=testdatabase;");
conn = new OdbcConnection(strCn);
strSql = "Select * from Contact";
}
public void connect(TextBox txtNam)
{
adapter = new OdbcDataAdapter();
OdbcCommand cmd = new OdbcCommand(strSql, conn);
adapter.SelectCommand = cmd;
dt = new DataTable();
conn.Open();
adapter.Fill(dt);
conn.Close();
txtNam.DataBindings.Add("Text", dt, "name");
}
}
Re: odbc connection to access- error
Well, earler I was getting the error below.
Exception Details: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Re: odbc connection to access- error
Quote:
Originally Posted by Shuja Ali
And the conenctionstring that you have pasted works perfectly with the ODBCConnection object.
Is there any other error that you are getting. It will also be helpful if you tell us what is the exact error message that you are getting and the exact code that you are using.
ya that particular line works....
this line
Code:
//strCn = ("Data Source=cntcal; Initial Catalog=testdatabase;");
was the line that did not work....mistake on my side.