Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I have a form with a textbox and two buttons. I use one button to open a OpenFileDialog box to choose a file, and the other button to add the chosen file name to a database.

 

The problem is that, If I type the path of the file in the textbox, it works fine, but if I choose it using the OpenFileDialog box, I get an error telling me that it couldn't find the database. The problem is that it looks for the database file in the same folder that I chose the file to add from.

 

I'm using access database, heres the connectionstring that I'm using

 

'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=""MediaDB.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False'

 

Any one knows whats going wrong????

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

Posted

'Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=""MediaDB.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False'

 

 

iebidan's right we're going to need to see some code... but that connectionstring... I've never seen one so long... do you actually use all those options?!?! :D :D

Posted
Some of those options repeat them selves - that may be what is causing you trouble.
Latly it would seem as though I'm don't abnegate from anything... except women. :( :)
  • Moderators
Posted

That connection string was probably setup using a wizard, if you want to set a DB file at runtime then you will need to set the entire connection string at runtime.

 

Either way runtime is the easiest way.

Visit...Bassic Software
Posted
Thats what I did, I set the connectionstring at runtime. But now I have another problem. My application copies files to a folder thats in the same folder as the application, I was using relative addressing ' for example, instead of using c:\myprog\media, I just use media', and it was working fine. But after I started using OpenFileDialog, I got these errors that the folder media is not found, it looks for the folder media in the same folder that I chose a file using OpenFileDialog.........

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

Posted (edited)

This happened to me in VB. When you use an OpenFileDialog, for some reason it switches the default folder to the folder that is picked in that. I fixed the problem by writing the path of the file to open as:

 

Application.StartupPath & "\NameOfFile"

 

Hope this helps.

Edited by Klogg
Take a look at my programs. Go to my web site.
Posted

If (Me.OpenFileDialog1.ShowDialog = DialogResult.OK) Then
           _filename = Me.OpenFileDialog1.FileName
           Me.txtFileName.Text = _filename
       End If

 

I use this on a buttons click event. As Klogg said, after I used the OpenFileDialog, the default folder changes to the folder that I navigated to...

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...