Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a connection string so people can download my applicatiin

Status
Not open for further replies.

softwareinvbnet

Programmer
Jul 23, 2013
2
MD
Hi, I am following a tutorial for vb.net here

I am using Windows 7 & Visual studio 2012 ultimate


In there tutorial the connection string looks like this
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:/AddressBook.mdb"

con.ConnectionString = dbProvider & dbSource

When I use this in debug mode it works

What I really want to know is this I want to be able to send this to someone else so they can download it and run it on there windows 7 computer.

So what I did was use the publish option in visual studio and when it published all my files to a folder I had created called databasetest. I then put it in a .rar and emailed it to myself but when I try to run it, I get the error message saying that it cant find C:/AddressBook.mdb
So can anyone help me learn how to do this.

Now if I move my AddressBook.mdb in to the root folder of my C drive it works. But I want to be able to just download and install. It seems a bit of a messy process if I have to keep moving files around after the install to make this work.
Thanks in advance for anyone's help.
 
If you have the connection string hard coded you will have to tell the setup application to put the database file where your application can find it (ie. C:\). You can specify when creating a setup where you would like a file copied to on the destination system.

I think it would be best if you had your application look for the mdb in the base directory of the app:

Code:
dbSource = "Data Source = " + AppDomain.CurrentDomain.BaseDirectory + "AddressBook.mdb"

Randy
 
Thanks for the reply, I am still wetting my feet wit VB.NET
My code now looks like this you can see I have commented out my original line and added what you said.

Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       
        'dbSource = "Data Source = C:/AddressBook.mdb"


        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = " + AppDomain.CurrentDomain.BaseDirectory + "\AddressBook.mdb"

        con.ConnectionString = dbProvider & dbSource
        con.Open()

        sql = "SELECT * FROM tblContacts"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "AddressBook")

        con.Close()

        MaxRows = ds.Tables("AddressBook").Rows.Count
        inc = -1

    End Sub



When I do it the way you said I get this error message.

Exception Text **************
System.Data.OleDb.OleDbException (0x80004005): Could not find file 'C:\Users\Nige\AppData\Local\Apps\2.0\2GKHLO4K.J93\4M6EYCZL.BJG\data..tion_406852d1df2764c8_0001.0000_9ff6234dc360b631\AddressBook.mdb'.



So can you help anymore? :)
 
Don't know why that is not working.

Try:
Code:
dbSource = My.Application.Info.DirectoryPath + "\AddressBook.mdb"

Here is image of my code and the output, both ways should produce similar results, one includes the trailing "\" and other one doesn't. But the are both giving me the directory of my EXE.

app_path.png
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top