Click here to Skip to main content
16,005,467 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Help with Session Pin
alexfromto1-Aug-06 4:49
alexfromto1-Aug-06 4:49 
GeneralRe: Help with Session Pin
Dave Kreskowiak1-Aug-06 5:08
mveDave Kreskowiak1-Aug-06 5:08 
GeneralRe: Help with Session Pin
alexfromto1-Aug-06 5:17
alexfromto1-Aug-06 5:17 
GeneralRe: Help with Session Pin
Dave Kreskowiak1-Aug-06 5:38
mveDave Kreskowiak1-Aug-06 5:38 
GeneralRe: Help with Session Pin
alexfromto1-Aug-06 6:48
alexfromto1-Aug-06 6:48 
GeneralRe: Help with Session Pin
Dave Kreskowiak1-Aug-06 9:43
mveDave Kreskowiak1-Aug-06 9:43 
Questionopenfiledialog disturbing database-connection? Pin
Smithers-Jones1-Aug-06 2:44
Smithers-Jones1-Aug-06 2:44 
AnswerRe: openfiledialog disturbing database-connection? Pin
Dave Kreskowiak1-Aug-06 4:46
mveDave Kreskowiak1-Aug-06 4:46 
This is caused by several problems. Not the least of which is that your connection string is not using a fully qualified path to the database file. You probably have something like:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.mdb

Right?

What you're doing is assuming that the database is in the current directory. The current directory can change at any time, like you've found out while using the OpenFileDialog.

Now, when the current directory changes, your next connection to the database fails because the .MDB file is no longer in the current directory. The correct way to do any kind of file access is to always specify fully qualified path names to your files, including inside connection strings. This way, none of your file access depends on the current directory being what it's supposed to be.
Public Shared Function GetConnectionString(ByVal databaseFilename As String) As String
    ' Build the fully qualified path to the file in the .EXE's startup folder.
    Dim fp As String = Path.Combine(Application.StartupPath, databaseFilename)
    Dim cs As String = String.Empty
    ' Check if the file exists...
    If File.Exists(fp) Then
        ' If so, build a connection string with it...
        cs = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", fp)
    Else
        ' If not, throw an exception...
        Throw New FileNotFoundException("The database file " & databaseFilename & " cannot be found in the application startup directory!")
    End If
    ' Return the completed connection string.
    Return cs
End Function



Dave Kreskowiak
Microsoft MVP - Visual Basic


GeneralRe: openfiledialog disturbing database-connection? Pin
Smithers-Jones2-Aug-06 2:12
Smithers-Jones2-Aug-06 2:12 
Questionscrollbar Pin
microuser_20001-Aug-06 2:31
microuser_20001-Aug-06 2:31 
AnswerRe: scrollbar Pin
Dave Kreskowiak1-Aug-06 4:50
mveDave Kreskowiak1-Aug-06 4:50 
GeneralRe: scrollbar Pin
microuser_20001-Aug-06 12:43
microuser_20001-Aug-06 12:43 
GeneralRe: scrollbar Pin
Dave Kreskowiak2-Aug-06 2:07
mveDave Kreskowiak2-Aug-06 2:07 
QuestionVB.NET & WSUS API - Reporting the status of a specific update per computer Pin
J Oliveira1-Aug-06 1:08
J Oliveira1-Aug-06 1:08 
Questionencrypt password Pin
md_refay1-Aug-06 0:50
md_refay1-Aug-06 0:50 
AnswerRe: encrypt password Pin
ii_noname_ii1-Aug-06 4:45
ii_noname_ii1-Aug-06 4:45 
GeneralRe: encrypt password Pin
ii_noname_ii1-Aug-06 4:54
ii_noname_ii1-Aug-06 4:54 
AnswerRe: encrypt password Pin
Nouvand3-Aug-06 2:02
Nouvand3-Aug-06 2:02 
Question(wav / mp3) file Pin
md_refay1-Aug-06 0:47
md_refay1-Aug-06 0:47 
Questionsetup package Pin
md_refay1-Aug-06 0:45
md_refay1-Aug-06 0:45 
QuestionMsgBox brainteaser Pin
ii_noname_ii1-Aug-06 0:42
ii_noname_ii1-Aug-06 0:42 
AnswerRe: MsgBox brainteaser Pin
Dave Kreskowiak1-Aug-06 5:06
mveDave Kreskowiak1-Aug-06 5:06 
GeneralRe: MsgBox brainteaser Pin
ii_noname_ii1-Aug-06 20:07
ii_noname_ii1-Aug-06 20:07 
GeneralRe: MsgBox brainteaser Pin
Dave Kreskowiak2-Aug-06 3:06
mveDave Kreskowiak2-Aug-06 3:06 
GeneralRe: MsgBox brainteaser Pin
ii_noname_ii2-Aug-06 20:10
ii_noname_ii2-Aug-06 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.