hi i have a program that uses ms access database in vb.net 2003, when i run the program it seems to work fine but if i press a button that uses an openfile dialogbox and try to open again my database the program crashes... it seems that is losing the path... can anyone help me pls? :'(

You would have to provide more details. Add the block of code that is causing the problem and also provide the exact error message.

the line of code that is causing the proble is the firs line of my code "me.adapter.fill(me.dataset.table)".my database is located in the bin folder of my applicationn, and in the generated code of my program there where it says Data source=""path"" i have erased the path and leave only the name of the database so it looks only in the bin folder to find it..

the error that gives me is "An unhandled exception of type "System.Data.OleDB.OleDBexception" occured in system.data.dll"

there that it sais Data source="path" i have inserted the whole path of my database and it works fine now, but i am afraid that it will not work on other pc because path will not be the same...how can i fix it?

there that it sais Data source="path" i have inserted the whole path of my database and it works fine now, but i am afraid that it will not work on other pc because path will not be the same...how can i fix it?

On other Pc's is the database always in the same location? Such as the app folder, or special folder such as User\Local Settings\Application Data?

If so there you can code to find the full paths for these type of locations. If not you would have to provide a way for the user to specify where the database file is located.

the database is allways in the bin folder of my application.. but when my application is installed on other pc it goes to adifferent path so the database can not be loaded

There is no bin folder after deployment installation but as long as the database is in the same folder as the app.exe you can use the Application.StartUpPath method to determine the path to that folder.

Dim strDbFileName As String = ""
Dim strDatabaseSource As String = ""

strDbFileName = "myDatabase.mdb"
strDatabaseSource = IO.Path.Combine(Application.StartupPath, strDbFileName)

this does not work because i haven't used connection string i have used wizards to create my dadabase connection... and the Data source=""path"" is in the generated code

Hi Tripes, that is fine and not a contradicition. The problem of course is that the wizard generated path is different on your computer then after you deploy. You can still set the database path to something different at run time. Once you create your valid database path at runtime, have it overwrite the existing saved setting.

can you please give me an example how to do that?

In your project properties you will see a settings tab, find out the name of your connection string setting. In coding you simply change it by assigning it a new value

My.Settings.ConnectionString1 = strMyNewConnectionStringVariable

If you need help with how to create a connection string, I can provide more info.

In your project properties you will see a settings tab, find out the name of your connection string setting. In coding you simply change it by assigning it a new value

My.Settings.ConnectionString1 = strMyNewConnectionStringVariable

If you need help with how to create a connection string, I can provide more info.

thank you for this. it will be useful if you provide more info.

yes please it will be very helpful if you provide more informations...

Plenty of info about saving and reading saved settings in the help file, just type My.Settings in the help index. To sum it up you can create setting in the window I previously mentioned, you need to create a name for each setting, set its datatype, scope and value. However you mentioned that a wizard already created this setting for you. To use/change the setting you need to determine what the setting name is.

i have tried your example but it doesn't work.. i am using vb.net 2003 if this helps you..

Oh the My.Settings is not something available in 03.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.