473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Connecting C# application with MS Access database

HI I have created a connection between C# application and MS ACCESS databse but when I am compiling it the error message ia displayed that file db1.mdb not found, please help me to figure out the solution?

This is my code:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data.OleDb;
  3.  
  4. class OleDbTest{
  5.  
  6. public static void Main()
  7. {
  8. OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\db1.mdb");
  9.  
  10.  
  11. OleDbCommand aCommand = new OleDbCommand("select * from emp_test", aConnection);
  12. try
  13. {
  14. aConnection.Open();
  15.  
  16. OleDbDataReader aReader = aCommand.ExecuteReader();
  17. Console.WriteLine("This is the returned data from emp_test table");
  18.  
  19.  
  20. while(aReader.Read())
  21. {
  22. Console.WriteLine(aReader.GetInt32(0).ToString());
  23. }
  24.  
  25.  
  26. aReader.Close();
  27.  
  28.  
  29. aConnection.Close();
  30. }
  31.  
  32.  
  33. catch(OleDbException e)
  34. {
  35. Console.WriteLine("Error: {0}", e.Errors[0].Message);
  36. }
  37. }
  38. }
Aug 24 '08 #1
7 2018
kenobewan
4,871 Expert 4TB
Here is a reference that may help:
This is a compiled connection strings reference list on how to connect to Access 2007.
Aug 24 '08 #2
NitinSawant
270 100+
did u wrote the correct connectionstring


Expand|Select|Wrap|Line Numbers
  1. Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Persist Security Info=False
  2.  
Aug 24 '08 #3
kenobewan
4,871 Expert 4TB
did u wrote the correct connectionstring


Expand|Select|Wrap|Line Numbers
  1. Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db1.mdb;Persist Security Info=False
  2.  
The OP is writing C# and I believe trying to avoid the single \ error...
Aug 25 '08 #4
Curtis Rutland
3,256 Expert 2GB
The OP is writing C# and I believe trying to avoid the single \ error...
Right.

But I think since the db's extension is .mdb, OP is using Acces 2003 or lower, so:
http://connectionstrings.com/?carrier=access
might be a better place to look.

Access 07 uses ACE instead of JET, so it probably wont work for older versions.
Aug 25 '08 #5
Right.

But I think since the db's extension is .mdb, OP is using Acces 2003 or lower, so:
http://connectionstrings.com/?carrier=access
might be a better place to look.

Access 07 uses ACE instead of JET, so it probably wont work for older versions.

thanks to All for reply, I got the solution
Aug 26 '08 #6
Curtis Rutland
3,256 Expert 2GB
thanks to All for reply, I got the solution
Please post your solution so other people might benefit.
Aug 26 '08 #7
Please post your solution so other people might benefit.

as such there is no problem with the code, the only thing was that I was not allowed to save the database directly on C drive
Aug 27 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dishaa V | last post by:
Hello I need to connect to an access db which is on the internet. I do know that URL of the same. its http://www.vallury.com/balance/bank.mdb. Its just a test db. How can I connect to that db...
7
by: carl.manaster | last post by:
I'm new to this game. I can find my way around C# without any trouble, and I've used Access, a little bit, in the past. Now a friend wants an application of mine to read from his Access database....
1
by: Tom Wild | last post by:
Hi I am trying to create a webform that connects to an Access database. If I use the connection string: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Gizmo\Gizmo.mdb" Then the application...
10
by: ej1008 | last post by:
HI all I am having a windows Control running on ASP.Net webform. From this windows control I am trying to connect to database to do some database operations. Now I am facing problem while...
12
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed...
5
by: Sebastian | last post by:
I'm using the following code to connect to an access 2000 database. (with reference to adodb) Public DBvar As New ADODB.Connection() DBvar.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data...
14
by: Peter | last post by:
I am trying to connect to a DB2 database with IBM.Data.DB2 provider and getting the following message ERROR SQL30081N A communication error has been detected. Communication protocol being...
2
by: Patrick F | last post by:
Hi, i have SQL Server 2005 and a database set that is called, myCompany the problem is that i cant connect from my page to it, here is from the web.config: ( i have got this connectionstring from...
3
by: Big Charles | last post by:
Hi, We have developed an ASP.NET web application and are planning to host it in an external Server, which provides us a good bandwidht. We need to put he web application outside because the...
2
by: orandov | last post by:
Hi, I am having a problem connecting my .net applications from the application server to the database server. When I run the application from my windows xp (sp2) box it works fine. When I try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.