Solved

OleDb.ExecuteNonQuery not using the correct path

Posted on 2011-02-28
4
564 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
  • 3
4 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now