|
-
May 7th, 2007, 08:01 AM
#1
Thread Starter
Lively Member
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
-
May 7th, 2007, 08:22 AM
#2
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
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 7th, 2007, 09:09 AM
#3
Thread Starter
Lively Member
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.
-
May 7th, 2007, 09:14 AM
#4
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.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 7th, 2007, 09:17 AM
#5
Thread Starter
Lively Member
Re: odbc connection to access- error
Hi,
thanks for replying...I would go thru these
-
May 7th, 2007, 09:21 AM
#6
Re: odbc connection to access- error
 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.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
May 7th, 2007, 09:43 AM
#7
Thread Starter
Lively Member
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");
}
}
Last edited by sunshine123; May 7th, 2007 at 09:51 AM.
-
May 7th, 2007, 09:48 AM
#8
Thread Starter
Lively Member
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
-
May 7th, 2007, 09:52 AM
#9
Thread Starter
Lively Member
Re: odbc connection to access- error
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|