Solved

Hide server password

Posted on 2009-04-06
4
283 Views
Last Modified: 2013-11-28
Due to a recent 'crackdown' in IT security all Access databases which connect to company servers must not have server passwords embedded in the connection string of attached tabledefs and stored querydefs.  With regard to tabledefs this is straightforward as the tables can simply be re-attached without dbAttachSavePWD as part of the attributes property.

However, since querydefs don't have an attributes property this appears to be more problematic.  For stored querydefs it seems that the only solution is to set the connection string to the DSN (or at least leave out the password) and then open one querydef
to force the default Login prompt to appear.  Once the user has successfully applied the password Access caches it and then subsequent querydefs opened on the same DSN automatically have the password applied.

This raises a problem of automation control, because it would be nice to capture the password in an Access form and then supply it to the dialogue box automatically, however this raises the prospect of the dreaded sendkeys and what to do if the user supplies the wrong password.  Can anyone suggest either a neat solution or an unequivecal statement that only temporary querydefs can be used in this situation.
0
Comment
Question by:Natchiket
  • 2
  • 2
4 Comments
 
LVL 17

Author Comment

by:Natchiket
ID: 24077270
I should qualify that, my reference to stored querydefs applies to stored passthrough querydefs
0
 
LVL 17

Author Comment

by:Natchiket
ID: 24077822
OK here's my working so far ... which *seems* to work for sybase with a DSN

Create a temporary querydef and open a recordset to validate the password.  If the password is valid then
instantiate any stored passthrough querydef (a nice simple one to be quick!)
use sendkeys to pass the password and an {enter} keystroke to the keyboard buffer
Open a recordset based on the querydef .... the ODBC password prompt briefly appears and autocompletes
voila ... all passthough querydefs work

a bit clunky ... any better ideas , anyone ?





0
 
LVL 16

Expert Comment

by:Chuck Wood
ID: 24108628
What I do is create an ADODB connection to the server, using the password, and then run queries. Each server database type requires a different connection string. The example in the snippet connects to an Access 2007 database but will not work with Access 2007. You will have to test it with Access 2003 as I do not have that version to validate the code.

Public Sub PasswordConnect()

'==========================================================

'  requires a reference to:

'    Microsoft ActiveX Data Objects 2.5(or later) Library

'==========================================================

    Dim cnn As ADODB.Connection

    Dim strDB As String, strDbPassword As String

    strDB = "\\Server\DB\myDatabase.mdb"

    strDbPassword = "myPassword"

    ' use an appropriate connection string

    ' for other connection strings see:

    ' http://www.connectionstrings.com/

    cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

        "Data Source=" & strDB & ";Jet OLEDB:Database Password=" & strDbPassword

    ' open the connection to the server

    cnn.Open

    ' run a query

    DoCmd.OpenQuery "myQuery"

    ' close the server connection

    cnn.Close

    ' clean up

    Set cnn = Nothing

End Sub

Open in new window

0
 
LVL 16

Accepted Solution

by:
Chuck Wood earned 500 total points
ID: 24108645
Oops. The phrase "will not work with Access 2007" should have been "will not work with Access 2000."
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Input box criteria 3 20
add more styles to my code 2 19
Access Run-time error '6' Overflow 5 13
select over clause 1 10
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now