app path adodb vb.net

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2007
Posts: 16
Reputation: jaytheguru is an unknown quantity at this point 
Solved Threads: 0
jaytheguru jaytheguru is offline Offline
Newbie Poster

app path adodb vb.net

 
0
  #1
Jun 23rd, 2008
Dear all, as always I am back with yet again a simple question.

I have developed an application in vb.net which has VB interface as front end and access 2003 as backend. The application path which I setup initially is :

  1. Dim MyConn As ADODB.Connection
  2. MyConn = New ADODB.Connection
  3. MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Lensesdb.mdb;"
  4. MyConn.Open()

here the access file is refering to C drive however, I want it to be within Application folder so that when I create the application, the file should be installed and ran directly from the application directory and not from C drive.

I have added the file into the compilation and it created the application (exe) fine however when I install the program and run it, it asks for the C:\Lensesdb.mdb file (says its missing) whereas the application file is within application folder.

I have found few ways online:
1st Example

  1. Public Function App_Path() As String
  2. Return System.AppDomain.CurrentDomain.BaseDirectory()
  3. End Function

2nd Example

  1. Private Function GetAppPath() As String
  2. Dim i As Integer
  3. Dim strAppPath As String
  4. strAppPath = System.Reflection.Assembly.GetExecutingAssembly.Location()
  5. i = strAppPath.Length - 1
  6. Do Until strAppPath.Substring(i, 1) = "\"
  7. i = i - 1
  8. Loop
  9. strAppPath = strAppPath.Substring(0, i)
  10. Return strAppPath
  11. End Function

I did bring them into my coding but I don't know how to refer to my application path when I type
  1. MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Lensesdb.mdb;"

how can I declare the the path so that I don't have to manually put it into the C drive of destination pc each time I install the application.

I hope I made some sense here

Regards

J
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: app path adodb vb.net

 
0
  #2
Jun 23rd, 2008
Hi
Try Application.StartupPath, It Gets the path for the executable file that started the application, not including the executable name.

Your Code might be

  1. MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath & "\Lensesdb.mdb;"
KSG
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 16
Reputation: jaytheguru is an unknown quantity at this point 
Solved Threads: 0
jaytheguru jaytheguru is offline Offline
Newbie Poster

Re: app path adodb vb.net

 
0
  #3
Jun 24th, 2008
Morning selvaganapathy,

I have tried your method however it didn't work. When I install the application and run it on a client machine it still comes up with the error message saying that the file cannot be found under C:\Lensesdb.mdb. However, When I put the file there it works absolutely fine.

I am using Visual Studio 2005 built in Setup Wizard to create setup file and yes I have added the mdb file while adding other files for the application. This though has not made any difference.

any other suggestion will be welcomed.

Many thanks

Regards

J
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: app path adodb vb.net

 
0
  #4
Jun 24th, 2008
Hi J,
Application.StartupPath will work fine. Problem may be

> You might created One or More connection (using c:\Lensesdb.mdb) and some of them are replaced as (Application.StartupPath & "\Lensesdb.mdb"), remaining not replaced.

> Database Connection using Wizard

These are my Guesses.
KSG
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 16
Reputation: jaytheguru is an unknown quantity at this point 
Solved Threads: 0
jaytheguru jaytheguru is offline Offline
Newbie Poster

Re: app path adodb vb.net

 
0
  #5
Jun 25th, 2008
Morning selvaganapathy,

The only place I can see it is declared as C:\lensesdb.mdb is under the config file and under settings.designer.vb Here is the sample code of the config file and the settings.designer.vb.

app.config
------------
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3. <configSections>
  4. </configSections>
  5. <connectionStrings>
  6. <add name="clLabApp.My.MySettings.LensesdbConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Lensesdb.mdb"
  7. providerName="System.Data.OleDb" />
  8. </connectionStrings>
  9. <system.diagnostics>
  10. <sources>
  11. <!-- This section defines the logging configuration for My.Application.Log -->
  12. <source name="DefaultSource" switchName="DefaultSwitch">
  13. <listeners>
  14. <add name="FileLog"/>
  15. <!-- Uncomment the below section to write to the Application Event Log -->
  16. <!--<add name="EventLog"/>-->
  17. </listeners>
  18. </source>
  19. </sources>
  20. <switches>
  21. <add name="DefaultSwitch" value="Information" />
  22. </switches>
  23. <sharedListeners>
  24. <add name="FileLog"
  25. type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
  26. initializeData="FileLogWriter"/>
  27. <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
  28. <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
  29. </sharedListeners>
  30. </system.diagnostics>
  31. </configuration>

Settings.designer.vb
-----------------------
  1. <Global.System.Configuration.ApplicationScopedSettingAttribute(), _
  2. Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
  3. Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.ConnectionString), _
  4. Global.System.Configuration.DefaultSettingValueAttribute("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Lensesdb.mdb")> _
  5. Public ReadOnly Property LensesdbConnectionString() As String
  6. Get
  7. Return CType(Me("LensesdbConnectionString"),String)
  8. End Get
  9. End Property
  10. End Class
  11. End Namespace

what should I do to that line where it says C:\Lensesdb.mdb? Shall I delete it? or shall i change it?

I have tried changing it to " &application......... " but it didn't work, though when I typed ..........Datasource=/Lensesdb.mdb" it didnt give me any errors.

whats your thoughts on that?

I'd like to thank you for your ongoing help however, if you help me little bit more I am sure I can achieve my goal

many thanks

Regards

J
Last edited by jaytheguru; Jun 25th, 2008 at 5:19 am.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 7
Reputation: regcure is an unknown quantity at this point 
Solved Threads: 0
regcure regcure is offline Offline
Newbie Poster

Re: app path adodb vb.net

 
0
  #6
Jun 30th, 2008
I think you have added the mdb file in the Setup wizard from C:\. First add the mdb file to your folder and hen you can use the Application.Startup properly as stated above. Then use the Setup Wizard to create the Setup files. This should solve the problem.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC