Need help with vb connection string

Status
Not open for further replies.

arian29

In the zone
can someone please help me with the code below, i am getting error "Expected )"

con.Provider = ("Microsoft.Jet.OLEDB.4.0;data source = " & App.Path & "\" & "vbox.mdb";Jet OLEDB:Database Password=qw34;Persist Security Info=False")
 

RCuber

The Mighty Unkel!!!
Staff member
can someone please help me with the code below, i am getting error "Expected )"

con.Provider = ("Microsoft.Jet.OLEDB.4.0;data source = " & App.Path & "\" & "vbox.mdb";Jet OLEDB:Database Password=qw34;Persist Security Info=False")
Is it VB 6 or VB.NET? I dont see any problem in the code.

If its VB.NET then you cannot assign the the Provider property as its readonly. Try like this
Code:
Dim ConnectionString As String = String.Empty
Dim WorkingDirectory As String = String.Empty
Dim DataBaseFile As String = String.Empty

WorkingDirectory = System.Environment.CurrentDirectory & "\"
DataBaseFile = WorkingDirectory & "\" & "vbox.mdb"
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataBaseFile & ";User ID=;Jet OLEDB:Database Password=qw34;"

Dim Con as New OleDBConnection ( ConnectionString )

If its VB 6 then try like this.

Code:
Dim ConnectionString As String = ""
Dim WorkingDirectory As String = ""
Dim DataBaseFile As String = "" 
Dim Con As ADODB.Connection

WorkingDirectory = App.Path & "\"
DataBaseFile = WorkingDirectory & "vbox.mdb"
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataBaseFile & ";User Id=admin;Password=qw34;"
Set Con = New ADODB.Connection
Con.Open ConnectionString
 

RCuber

The Mighty Unkel!!!
Staff member
if possible post the source where you are getting the error. post a screen shot if possible.
 
OP
A

arian29

In the zone
[FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica] now i am getting "object required"[/FONT][/FONT]
 
OP
A

arian29

In the zone
[FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica] Private Sub CommandButton1_Click()

Set con = CreateObject("ADODB.connection")
Set rs = CreateObject("ADODB.recordset")
Set cmd = CreateObject("ADODB.command")
con.Provider = ("Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=asd123;data source = " & App.Path & "\" & "vbox_db.mdb;Persist Security Info=False")
con.Open App.Path & "\vbox_db.mdb"
[/FONT][/FONT]
 

RCuber

The Mighty Unkel!!!
Staff member
Dude, Replace you code with this one. It should work.
Code:
Private Sub CommandButton1_Click()
Dim ConnectionString As String = ""
Dim WorkingDirectory As String = ""
Dim DataBaseFile As String = "" 
Dim Con As ADODB.Connection

WorkingDirectory = App.Path & "\"
DataBaseFile = WorkingDirectory & "vbox.mdb"
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataBaseFile & ";User Id=admin;Password=qw34;"
Set Con = New ADODB.Connection
Con.Open ConnectionString
.
.
.

End Sub
 
OP
A

arian29

In the zone
Dude, Replace you code with this one. It should work.
Code:
Private Sub CommandButton1_Click()
Dim ConnectionString As String = ""
Dim WorkingDirectory As String = ""
Dim DataBaseFile As String = "" 
Dim [COLOR=Red][B]Con As ADODB.Connection[/B][/COLOR]

WorkingDirectory = App.Path & "\"
DataBaseFile = WorkingDirectory & "vbox.mdb"
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataBaseFile & ";User Id=admin;Password=qw34;"
Set Con = New ADODB.Connection
Con.Open ConnectionString
.
.
.

End Sub
am getting "User-Defined type not defined"
 

RCuber

The Mighty Unkel!!!
Staff member
Sorry for the delay .. I missed this thread.You get this error because you havent added a reference to ado in your project. Please add a reference to "Microsoft ActiveX Data Objects Library" and this should work.
 
Status
Not open for further replies.
Top Bottom