can anyone plz help me out by giving the lines of code which will hwlp me establisg a connection with my access database usin ADO ......

Dani AI

Generated

A few practical notes on encrypting an Access file and opening it from VB (ties together points from and ):

Access encryption basics — two different things exist: the simple "database password" (what Access calls Encrypt/Set Database Password) and the older user-level/workgroup security model (mdw). The database password encrypts the file so Access requires a password to open it; user-level security is different and mainly applies to .mdb files and multi-user permissioning. Always back up the .mdb/.accdb first and put the file into exclusive mode before applying or removing a password.

How to open an encrypted DB from VB (no need to "decrypt" the file first): include the database password in the connection string and open with ADO. Example connection-string lines you can use in VB (match provider to your file type and installed engine):

' For an older .mdb (Jet)
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Path\MyDb.mdb;Jet OLEDB:Database Password=MyPassword;"

' For .accdb (ACE)
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Path\MyDb.accdb;Jet OLEDB:Database Password=MyPassword;"

Security and deployment notes: do not hard-code passwords in source. Use secure config storage or prompt at runtime. The client machine must have the matching provider (Jet vs ACE) and bitness (32/64-bit) available. Access database passwords on older Jet (.mdb) are not strong protection — for sensitive data use a server DB (SQL Server) with proper authentication and encryption. If you need to set or change a database password programmatically, use Access tooling or APIs (DAO CompactDatabase or ADOX) rather than trying to edit the file directly; both require exclusive access and the correct engine installed.

Recommended Answers

All 9 Replies

This is Salami Quadri
Ado programming is just a simple thing, the following steps are to be taking
1. click on project in the menu bar
2. select Component from the drop down menu
3.Microsoft ADO data control 4.0
Then click ok
4. Click on apply and ok
The control is added to the tool box, double click on it to place the control on the form
Change the name and other properties like
DatabaseName click on ... displayed at the right corner of this property to browse the name.

If you don't want to use a control (I never use one) then simply add Microsoft ActiveX Data Objects 2.1 Library in references. Then use the ADODB.Connection and ADODB.Recordset objects.

See here for a run down of ADO

And here for an Access (or any other) connection string

http://www.connectionstrings.com/

Hence you would do

Dim objConn as ADODB.Connection
Dim objRst as ADODB.Recordset
Dim lngRecordCount as Long

Set objConn = New ADODB.Connection
objConn.Open "[connectionstring]"

Set objRst = objConn.Execute("[SQL]", lngRecordCount)

Remember to set the connection string and SQL to what you actually want

I am astonished to find too many people asking the question of connectivity of database and vb.

First try to understand the properties of a connection object. You tell your ADO which database you want to contact, supply your user name and password (so the DBMS can grant you access to the database) and allow you to read,modify etc as per the previlages set for your user name. Actually the connection object is the gateway to any database.

If you open a code window of a new data project (EXE project you should have added a reference to the ADODB library) you can declare a connection object as follows:

Dim myConnection AS ADODB.Connection.

The moment you finish typing the dot(period) after the ADODB, you can see a vast list of objects with the ADO component, and you can select the one you want by the arrow keys. Declare the myConnection Object in the Code modules's declaration section. Then place the command button on the Form, name it myAccess Connection, and in the click event enter the following:

Sub Command1_click()
myConnection.ConnectionString =
"provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source = C:\Program Files\VB98\Nwind.mdb"
myConnection.Open
End Sub


The ampersand if you are using, kindly give a space before and after.
This will establish for you a connection to ACCESS NWind Database in the path shown by Data Source = c:\.....
If you want to know more please ask in the thread.

thanx fr ur help......but a problem is still there

Dim dbUserName As ADODB.Connection
Dim rsUserName As ADODB.Recordset

Set dbUserName = New ADODB.Connection
dbUserName.Open ("db1")
''dbUserName.Open "dsn=db1"
Set rsUserName = dbUserName.Execute("Select * from table ")
Do Until rsUserName.EOF
CboUserName.AddItem _
rsUserName("UserName")
CboPassword.AddItem _
rsUserName("Password")
CboPassword.ItemData(CboPassword.NewIndex) = rsUserName("Serialno")
CboUserName.ItemData(CboUserName.NewIndex) = rsUserName("Serialno")
rsUserName.MoveNext
Loop
dbUserName.Close

in the above code db1 is my database name for which i hv already created the user dsn....CboUserName and CboPassword are the two comboboxes that i hv used in my form
when i compile this code in the form load event ....it is giving an error in the "from clause" of the SQL statement...


can u plz help me out with this

Firstly have you checked that the connection is being established correctly, secondly what is the error

ya....connection has been established....its giving an error in the execute statement where i am executing the SQL query......its giving an error in the from clause.....

do tell me wat all refrences i need to add in my VB for opening up the database connection and executing the SQl query.....


i think i m nt being able to set up the connection.....wt mite be the problem???
plz tell me....

Please confirm by return post whether you are connecting to Access Db or MsSql Server version of the database. Then only your problem can be solved.
By the time I am writing the code for you for a cut and paste on the thread.

thanx....the problem is solved now.....it ws a connection problem only.....

i need 1 another help ....how can i encrypt my database.....
nd then how can i access that encryptd database from VB....
will i hv to decrypt it for accessing it.....nd if yes then how do i decrypt it also in VB

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.