Solved

OleDb.ExecuteNonQuery not using the correct path

Posted on 2011-02-28
4
561 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Figured it out myself
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

10 Experts available now in Live!

Get 1:1 Help Now