Solved

OleDb.ExecuteNonQuery not using the correct path

Posted on 2011-02-28
4
570 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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

635 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