473,387 Members | 1,766 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,387 software developers and data experts.

SaveFileDialog changes connectionString!

344 100+
Hello,

I'm facing something odd with ConnectionString; when I use a SaveFileDialog the connection string changes to the location I've chosen in the SaveFileDialog.

Here is how I implement that:
Expand|Select|Wrap|Line Numbers
  1.         static OleDbConnection connection = new OleDbConnection
  2.             (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\db1.mdb;Persist Security Info=True");
  3.  
Anyone has an idea?

Thanks in advanced!
May 10 '10 #1
7 1796
Bassem
344 100+
I'm sorry I forgot to post what gives the exception and the exception itself!

Here is:
Expand|Select|Wrap|Line Numbers
  1.             try
  2.             {
  3.                 OleDbDataAdapter adapt = new OleDbDataAdapter(commandText, connection);
  4.                 DataSet ds = new DataSet();
  5.                 adapt.Fill(ds);
  6.                 return ds;
  7.             }
  8.             catch
  9.             {
  10.                 connection.Close();
  11.             }
  12.  
It breaks on adapt.Fill(ds); and the exception message:
"Could not find file 'C:\Documents and Settings\Mr. Bassem\Desktop\db1.mdb'."


Thank you for your time!
May 10 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
Whether "db1.mdb" file is placed in "C:\Documents and Settings\Mr. Bassem\Desktop" folder?

I suspect after you are done with SaveFileDialogue your app still points to the same location and try to get that .mdb file from there.

Regards
Dheeraj Joshi
May 11 '10 #3
Bassem
344 100+
Thank you Dheeraj,

My database is stored as exactly I created the connection string in the application start up path, exactly where my exe is.

You are right, for some reason the application points to where the SaveFileDialog points, but I checked the connection string and it is the same as I initialized (never changed).

I think I don't know if that bug is related or not to the connection string!


Thank you for your help!
May 11 '10 #4
Bassem
344 100+
Hi I found the problem and fixed it.

in my command text I typed: "db1.table1" in a select query, when I changed it to "table1" and removed "db1" everything worked fine.

I wonder what happened there!!!

Anyone has an idea?!

Thanks for your help!
May 11 '10 #5
Plater
7,872 Expert 4TB
Well SaveFileDialog will change your working directory I think. (I also believe there is a property you can set so that it does NOT do that)
So it might have something to do with using relative paths in your connection string?
May 11 '10 #6
Bassem
344 100+
Thanks Plater,

Yes, I think you have defined the problem well.

That property should be related to the application, right?
May 11 '10 #7
Plater
7,872 Expert 4TB
I believe it is the RestoreDirectory property on your SaveFileDialog
May 11 '10 #8

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

Similar topics

6
by: Ken Allen | last post by:
I have enocuntered something wierd. If I invoke an instance of the above dialog and elect to save the file in a directory where a file of that name does not exist, then the return is...
2
by: Dennis C. Drumm | last post by:
Is there a way for the parent that calls the SaveFileDialog.ShowDialog to consume events associated with this dialog such as LocationChanged, Moved and Closed events? I had been working on a way...
5
by: juli | last post by:
Hello dear fellows! Is there any chance that you know how can I upload a file with the saveFileDialog control to a specific folder-> I want any file uploaded to be save on specific folder with...
3
by: josh | last post by:
How do I make it actually save or open a file? It only opens the dialogs. What do I type to get it to save? Here's what I have so far: Public Class frmMainApp Inherits...
8
by: Ben R. | last post by:
Hi all, This is a multipart question. I’ve got an asp.net site that contains an access database. Previously, I would debug by making changes and uploading to my host. Now, I’d like to be...
2
by: ad | last post by:
Hi, I want to use saveFileDialog to save a file (like c:\aa.zip) to another place. How can I assgin c:\aa.zip to saveFileDialog
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
2
by: jehugaleahsa | last post by:
Hello: Correct me if I'm wrong, but it appears that saving a file with the SaveFileDialog changes the Environment.CurrentDirectory property. How can I prevent this? Thanks, Travis
8
by: Joe Duchtel | last post by:
Hello - I have the following code to detemine a file name when my application is saving a file. The problem is that if the file already exists and I select the Yes button in the "Do you want to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.