# Need help with vb connection string



## arian29 (Aug 18, 2008)

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 OLEDBatabase Password=qw34;Persist Security Info=False")


----------



## RCuber (Aug 18, 2008)

arian29 said:


> 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 OLEDBatabase 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 

```
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.


```
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
```


----------



## arian29 (Aug 20, 2008)

i did that but its still not working  , its for vb6


----------



## RCuber (Aug 20, 2008)

if possible post the source where you are getting the error. post a screen shot if possible.


----------



## arian29 (Aug 23, 2008)

[FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica] now i am getting "object required"[/FONT][/FONT]


----------



## RCuber (Aug 23, 2008)

^^ check your PM


----------



## arian29 (Aug 24, 2008)

[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 OLEDBatabase Password=asd123;data source = " & App.Path & "\" & "vbox_db.mdb;Persist Security Info=False")*
con.Open App.Path & "\vbox_db.mdb"[/FONT][/FONT]


----------



## RCuber (Aug 24, 2008)

Dude, Replace you code with this one. It should work.

```
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
```


----------



## arian29 (Aug 25, 2008)

Charan said:


> Dude, Replace you code with this one. It should work.
> 
> ```
> Private Sub CommandButton1_Click()
> ...


am getting "User-Defined type not defined"


----------



## RCuber (Sep 2, 2008)

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.


----------

