|
-
Jul 26th, 2013, 05:39 PM
#1
Thread Starter
New Member
connection string does not work for local database running windows 7
Hi all,
I am following a tutorial at http://www.homeandlearn.co.uk/NET/nets12p4.html
When I run there programme in debug mode it works great, the problem is when I try to run there programme on another computer I have running Windows 7.
I am using Visual studio ultimate 2012 to learn with and my Operating system is Windows 7.
All I am trying to achieve is make this small programme run on another computer
I have been to lot's of different forums and searched the net high and low for my answer but I can get it to work. OK here goes in debug mode it works. So I created a folder on my desktop and called it "databasetest" I then used the publish option which comes with VS2012 and published this app to my new folder I created on the desktop. I then click on the .exe file to install the software and it appears to install fine but then I get this error when I try to run it.
Code:
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'.
**My code is **
Option Strict On
Option Explicit On
Public Class Form1
Dim inc As Integer
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim MaxRows As Integer
Dim fldr As String
Dim Builder As New OleDb.OleDbConnectionStringBuilder
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'dbSource = "Data Source = C:\Program Files\databasetest\databasetest2\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
Private Sub NavigateRecords()
txtFirstName.Text = CStr(ds.Tables("AddressBook").Rows(inc).Item(1))
txtSurname.Text = CStr(ds.Tables("AddressBook").Rows(inc).Item(2))
End Sub
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
Else
MsgBox("First Record")
End If
End Sub
Private Sub btnLast_Click(sender As Object, e As EventArgs) Handles btnLast.Click
If inc <> MaxRows - 1 Then
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
Private Sub btnFirst_Click(sender As Object, e As EventArgs) Handles btnFirst.Click
If inc <> 0 Then
inc = 0
NavigateRecords()
End If
End Sub
End Class
You will notice I have changed the connection string slightly from the tutorial which I did under someone Else's guidance.
in the tutorial is shows the connection string as being
dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
dbSource = "Data Source = C:/AddressBook.mdb"
What I really want is someone to show me how I can get this small application to install on another computer running Windows 7.
It would also be good if someone out there had a small application that I could maybe download from them along with the source code so I can see it working. I am just wanting to learn how to attach and use a local database with software I create Any guidance is very much appreciated.
Thanks.
Tags for this Thread
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
|