?
Solved

OleDb.ExecuteNonQuery not using the correct path

Posted on 2011-02-28
4
Medium Priority
?
571 Views
Last Modified: 2012-05-11

I create an OleDbCommand, giving it a connection that I know ought to work.  Just before I execute this command:

int retval = cmd.ExecuteNonQuery();

...I look at the values in the OleDbCommand object cmd.

The Connection’s connection string is: "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\francine\\Winform.Finance\\Finance.mdb;"

…and the connection’s DataSource is: "C:\\francine\\Winform.Finance\\Finance.mdb"

…but when I execute it, an OleBdException is thrown:  {"Could not find file 'C:\\francine\\Winform.Finance\\bin\\Debug\\dbo.mdb'."}

Does anybody know why it might be losing the name of the database?
0
Comment
Question by:FrancineTaylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 13

Expert Comment

by:Rahul Agarwal
ID: 35004202
Try This:

Put the database in App_Data folder and

then change your Datasource path to

Source=|DataDirectory|\Finance.mdb
 
0
 
LVL 1

Author Comment

by:FrancineTaylor
ID: 35014269
I changed the pathname to access the App_Data folder.  The code now reads:

OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\francine\\Crystal Applications\\Crystal.Winform.Finance\\App_Data\\Finance.mdb;");
            conn.Open();
            OleDbCommand cmd = new OleDbCommand("INSERT INTO dbo.trans(description) VALUES('Description')", conn);
            int retval = cmd.ExecuteNonQuery();

When I hit the ExecuteNonQuery line, it throws the same error:

{"Could not find file 'C:\\francine\\Crystal Applications\\Crystal.Winform.Finance\\Crystal.Winform.Finance\\bin\\Debug\\dbo.mdb'."}

The path works fine for other commands on that database.  Tables were created, records inserted into those tables, etc.  The tran table was just created previous to this command ("CREATE TABLE [trans](ID int IDENTITY PRIMARY KEY, Description VARCHAR(50)")

It isn't until I try to insert a record into the trans table that the error is thrown.
0
 
LVL 1

Accepted Solution

by:
FrancineTaylor earned 0 total points
ID: 35048228
Okay, never mind.  I found the error.  It was throwing an error on the INSERT statement that I was trying to execute because one of the string values that I was inserting just happened to have a single quote in the data, and that threw off the whole statement.

Not sure why it was getting a .NET error instead of an SQL error, but there it is.
0
 
LVL 1

Author Closing Comment

by:FrancineTaylor
ID: 35106999
Figured it out myself
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question