Problem deploying EXE

ShiftySid

Member
Joined
Mar 7, 2005
Messages
15
Programming Experience
3-5
Hi guys, I have a problem that's been bugging me for ages and I' hoping someone will be able to help me out.

I have written VB.Net front-end to an access database. Running on my development computer, it's fine because the path to the database is hard-coded (ie: D:\VBProjects\Datasource\data.mdb).

However, as soon as I copy the EXE (even if using the deployment wizard and including the MDB source files) to another PC, and run it - it always generates an error because the path to the MDB can not (obviously) be found - as it's still looking in the original location (ie: D\VBProjects... etc).

My question is this. Other than creating folders of the same name on the remote PC, so that the path is found - how can I make it so that the MDB is picked up automatically, or even code it so that I can deploy my database front end EXE to several PC's and store the database on just one PC?

It's driving me mad and if anyone has the answer, I will forever be in their debt!

Thanks,

Shifty.
 
Use either config file or XML ... well you can also use comma separated file or just a text file but previous two are preferable. Enter the connection string there. Then when you deploy the app just change the path to new location either local or network if you decide to store certain Access file on the server machine. Means all you need is reading of i.e. XML file getting connection string on Load event. If you are not satisified by the answer i will make a demo for you :)
Regards ;)
 
Thanks for this. A demo would be much appreciated if you have the time. I am just a beginner and I've never used XML files before.

Thanks,

Shifty.
 
I'm really sorry to say this... but it doesn't quite work for me. The problem I have, is that I used a DataGrid which was populated by an OleDbDataConnection, and OleDbDataAdapter and a DataSet.

When adapting your sample, because you were using a ListView it rendered the rest of my app useless.

Here is a sample of my code for the form load event:

DsStock1.Clear()
OleDbDataAdapter1.Fill(DsStock1)

' Get the width of the Longest Field.
Dim newwidth As Integer = LongestField(DsStock1, "tblStockControl", "Item")

' Create new Table Style.
Dim ts As New DataGridTableStyle
ts.MappingName = "tblStockControl"
dgStock.TableStyles.Clear()
dgStock.TableStyles.Add(ts)

' Assign New Width to DataGrid column.
dgStock.TableStyles("tblStockControl").GridColumnStyles("Item").Width = newwidth


How could that be modified to use your text-based connection string?

I also need to be able to save changes back to the underlying database, and currently use the following code:

Try
OleDbDataAdapter1.Update(DsStock1)
Timer1.Enabled = True
Timer1.Start()
Catch ex As Exception
MsgBox(ex.ToString)
End Try


So again, this is no good when using the ListVew.

If possible, if you could do another quick demo using my methods it would be much appreciated.

Thanks,
Shifty.
 
Ok even i do not like the DataGrid control (actually i hate it) i made a demo for you. Notice that it doesn't differ from the first example at least not regard connection string. It is pretty same except that DataGrid looks very odd :D lol
However you suppose to declare a new stuff in order to populate datagrid.
1st add these declarations in the current class with class scope or declare them as public in the existing module:

VB.NET:
Dim data As DataTable
Dim da As oledbDataAdapter
Dim cb As OleDbCommandBuilder

then just join these lines to the button "Populate dataGrid":

VB.NET:
Try
oledbcon.Open()
data = New DataTable
da = New OleDbDataAdapter("SELECT * FROM Members", oledbcon)
cb = New OleDbCommandBuilder(da)
da.Fill(data)
dataGrid.DataSource = data
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
oledbcon.Close()
End Try

HTH
Regards ;)
 

Attachments

  • ConnectionPathIssue.zip
    41.2 KB · Views: 26
Thanks. That seems to work ok. Just two more things (sorry!) could you please tell me how to:

1) Make the columns of the datagrid adjust automatically to the width of the widest column? My previous code was:

dgStock.TableStyles("tblStockControl").GridColumnStyles("Item").Width = newwidth

but that doesn't work with the new code you supplied!

2) What would the code be in order to save changes made to the datagrid - I previously used the DataAdapter and the code was:

OleDbDataAdapter1.Update(DsStock1)

but now I am not using the DataSet.

Please help - I am confused!
 
i'm a little late here, but i always plan on the database being in the same folder as the exe file (or in a subfolder of the folder where the exe is)

in which case i use Applicaiton.StartupPath & "\Access.mdb" 'Where Access.mdb is the actual database
 
JuggaloBrotha said:
i'm a little late here, but i always plan on the database being in the same folder as the exe file (or in a subfolder of the folder where the exe is)

in which case i use Applicaiton.StartupPath & "\Access.mdb" 'Where Access.mdb is the actual database

What if MSAccess file is in the folder of the computer from Local Network .. then? lol :)
 
Back
Top