|
-
Apr 10th, 2003, 11:31 AM
#1
Thread Starter
Addicted Member
Relative path to mdb file
Is there a way I can specify a relative path to my mdb file instead of an exact path as showing below:
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\VB Project\FormPractice\Login\Scholarship.mdb"
I have tried: Data Source=C:\...\Scholarship.mdb but this doesn't work. I also tried this: Data Source=Data\Scholarship.mdb but same thing happened. I receive an error.
Many thanks in advance!
Chong
-
Apr 10th, 2003, 11:39 AM
#2
Addicted Member
You can use your Application.StartupPath variable to create an absolute path based on relative information, etc. But you have to use an absolute path.
-
Apr 10th, 2003, 12:25 PM
#3
Sleep mode
This would be more practical :
VB Code:
Private Shared My_Path As String = Application.StartupPath & "\webdb.mdb"
Private Shared My_Password As String = "YOUR PASSWORD"
Private Shared My_Connection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyPath & ";Jet OLEDB:Database Password=" & MyPassword)
-
Apr 10th, 2003, 12:49 PM
#4
Thread Starter
Addicted Member
Thanks for helping me. However, this is the error I got after I follow your suggestion.
An unhandled exception of type ‘System.Data.OleDb.OleDbExcetion’ occurred in system.data.dll
I have always received this error if I did not put an exact path to the data source. I did a step by step debug and by using the application.startup variable, I was able see the correct path but after the cn.open(), the application just crashed with the above error.
Chong
-
Apr 10th, 2003, 11:02 PM
#5
Sleep mode
Check database name , path or post some of your code to see what's wrong ?
-
Apr 11th, 2003, 01:33 AM
#6
Lively Member
Catch Exception
Originally posted by Chong
Thanks for helping me. However, this is the error I got after I follow your suggestion.
I have always received this error if I did not put an exact path to the data source. I did a step by step debug and by using the application.startup variable, I was able see the correct path but after the cn.open(), the application just crashed with the above error.
Chong
VB Code:
Try
cn.open()
Catch dbException as System.Data.OleDb.OleDbException
Messagebox.show(dbException.message)
End Try
use above code to show what was the error occured
-
Apr 11th, 2003, 08:30 AM
#7
Thread Starter
Addicted Member
Thanks! It's working now. I didn't know that the application.startup starts in the bin folder. I put the mdb files in there and it's working now.
Again, thanks!
Chong
-
Apr 11th, 2003, 09:37 AM
#8
Sleep mode
errors regarding paths in ado.net can't be shown when using try...catch structure .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|