Using VB.NET

I have the path to my Access file stored in an App.config file:

<add key="constring" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Data/METL.mdb;Persist Security Info=False"/>

I usually set the connection like this:

'* Get the appSettings constring value (set in the web.config)
strConstring =
System.Configuration.ConfigurationSettings.AppSettings("constring")

'* Connects to database
ocnConnection = New OleDb.OleDbConnection(strConstring)

After creating an Excel file and saving it to a folder other than the
application folder, my database connections always try to find the database
file in the folder the Excel file was saved to.

If dlgSaveFile.ShowDialog() = DialogResult.OK Then
Excel.DisplayAlerts = False
Excel.AlertBeforeOverwriting = False
Excel.ActiveWorkbook.SaveAs(dlgSaveFile.FileName)
Excel.ActiveWorkbook.Close()
Else
Excel.ActiveWorkbook.Close(False)
End If


Thanks,

Sacha

Re: Data path changes after saving files with SaveFileDialog by Sacha

Sacha
Fri Apr 01 19:54:29 CST 2005

I found the solution. After saving, I needed to change the current directory
back to the executing assemblies directory:

Directory.SetCurrentDirectory(System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0,
System.Reflection.Assembly.GetExecutingAssembly.Location.LastIndexOf("\") +
1))

Thanks,

Sacha



"Microsoft News Server" <korell@knology.net> wrote in message
news:%23CcpGzvNFHA.1096@tk2msftngp13.phx.gbl...
> Using VB.NET
>
> I have the path to my Access file stored in an App.config file:
>
> <add key="constring" value="Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=Data/METL.mdb;Persist Security Info=False"/>
>
> I usually set the connection like this:
>
> '* Get the appSettings constring value (set in the web.config)
> strConstring =
> System.Configuration.ConfigurationSettings.AppSettings("constring")
>
> '* Connects to database
> ocnConnection = New OleDb.OleDbConnection(strConstring)
>
> After creating an Excel file and saving it to a folder other than the
> application folder, my database connections always try to find the
> database file in the folder the Excel file was saved to.
>
> If dlgSaveFile.ShowDialog() = DialogResult.OK Then
> Excel.DisplayAlerts = False
> Excel.AlertBeforeOverwriting = False
> Excel.ActiveWorkbook.SaveAs(dlgSaveFile.FileName)
> Excel.ActiveWorkbook.Close()
> Else
> Excel.ActiveWorkbook.Close(False)
> End If
>
>
> Thanks,
>
> Sacha
>