943,724 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 6149
  • VB.NET RSS
Jun 23rd, 2008
0

app path adodb vb.net

Expand Post »
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 :

VB.NET Syntax (Toggle Plain Text)
  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

VB.NET Syntax (Toggle Plain Text)
  1. Public Function App_Path() As String
  2. Return System.AppDomain.CurrentDomain.BaseDirectory()
  3. End Function

2nd Example

VB.NET Syntax (Toggle Plain Text)
  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
VB.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaytheguru is offline Offline
18 posts
since Aug 2007
Jun 23rd, 2008
0

Re: app path adodb vb.net

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

VB.NET Syntax (Toggle Plain Text)
  1. MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & Application.StartupPath & "\Lensesdb.mdb;"
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jun 24th, 2008
0

Re: app path adodb vb.net

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaytheguru is offline Offline
18 posts
since Aug 2007
Jun 24th, 2008
0

Re: app path adodb vb.net

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.
Reputation Points: 44
Solved Threads: 101
Posting Pro
selvaganapathy is offline Offline
547 posts
since Feb 2008
Jun 25th, 2008
0

Re: app path adodb vb.net

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
------------
VB.NET Syntax (Toggle Plain Text)
  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
-----------------------
VB.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jaytheguru is offline Offline
18 posts
since Aug 2007
Jun 30th, 2008
0

Re: app path adodb vb.net

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
regcure is offline Offline
7 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: How to get freelancing software projects to work from home - Please Help
Next Thread in VB.NET Forum Timeline: opening a new project





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC