?
Solved

Connection to ODBC - hardcode password

Posted on 2003-03-27
11
Medium Priority
?
943 Views
Last Modified: 2010-06-17
Hi,

I've got the following code:

--------
myConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security " & _
         "Info=False;Data Source=c:\test.mdb;Pwd=passhere;"
--------

And this link has a password, but I can't seem to hardcode the password in. It doesn't seem to work. Can anyone help me please.

When I link to the database, the userid is already filled in, via the DSN, it's just the password needs to be filled in.

I've tried using:
myConn.Attributes = dbAttachSavePWD

but that doesn't hold the password.

By the way - the code connects to the database, if the code is true then an event happens, if the code is false then it waits 15 secs and tries again. Therfore connecting to the database again.

Thanks.


0
Comment
Question by:dj_humpyg
  • 6
  • 4
11 Comments
 
LVL 1

Accepted Solution

by:
rafsalman earned 150 total points
ID: 8217469
Public Function CreateAccessDSN(strDSNName As String, _
                                strDBPath As String, _
                                intAction As Integer) As Boolean
'***************************************************************************
'Purpose:     Creates an Access DSN.
'Parameters:  strDSNName - DSN Name to be created.
'             strDBPath  - Path of the database.
'             intAction  - Type of DSN to be created. (See Consts)
'Returns:     True/False - DSN created.
'***************************************************************************
   
Dim lngRetVal As Long
Dim strDriver As String
Dim strAttributes As String
   
  CreateAccessDSN = False
   
  strDriver = "Microsoft Access Driver (*.mdb)" & Chr(0)
 
  strAttributes = "DSN=" & strDSNName & Chr(0)
  strAttributes = strAttributes & "Uid=" & Chr(0) & "pwd=" & DB_PASSWORD & Chr(0)
  strAttributes = strAttributes & "DBQ=" & strDBPath & Chr(0)
 
  lngRetVal = SQLConfigDataSource(0, intAction, strDriver, strAttributes)
 
  If lngRetVal = 1 Then CreateAccessDSN = True
0
 

Author Comment

by:dj_humpyg
ID: 8217663
Thanks for the quick reply.

I've added the code but it's still popping up with the 'Oracle8 ODBC Driver Connect' window asking for my password.

I didn't specify Oracle ODBC in the first instance, so not sure if this is why it still isn't working.

Thanks.
0
 

Author Comment

by:dj_humpyg
ID: 8217724
Thanks for the quick reply.

I've added the code but it's still popping up with the 'Oracle8 ODBC Driver Connect' window asking for my password.

I didn't specify Oracle ODBC in the first instance, so not sure if this is why it still isn't working.

Thanks.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:rafsalman
ID: 8217801
ah, the code was for an Access DB.

Not sure if Oracle works the same way - sorry.
May be worth posting this to Oracle Database area if you don't get an answer here in a reasonable amount of time.

Can you see the password in your registry?

The above code will create the registry setting.


To read it and open you would need something liken (for access anyway)

DBConnection.open DSN

where DSN = strDSNName in the first part of code
0
 

Author Comment

by:dj_humpyg
ID: 8217806
Thanks for the quick reply.

I've added the code but it's still popping up with the 'Oracle8 ODBC Driver Connect' window asking for my password.

I didn't specify Oracle ODBC in the first instance, so not sure if this is why it still isn't working.

Thanks.
0
 
LVL 1

Expert Comment

by:rafsalman
ID: 8217876
dj, use the "reload this question" rather than refresh to avoid posting multiple copies ;)

If you want to not do this that is!
0
 

Author Comment

by:dj_humpyg
ID: 8217892
Thanks for the quick reply.

I've added the code but it's still popping up with the 'Oracle8 ODBC Driver Connect' window asking for my password.

I didn't specify Oracle ODBC in the first instance, so not sure if this is why it still isn't working.

Thanks.
0
 
LVL 3

Expert Comment

by:n_narayanan
ID: 8218063
Hi

I am assuming that you have a database password for access database.

In that case the connection string should be,

myconn.open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
 "Data Source=c:\test.mdb;" & _
 "Jet OLEDB:Database Password=passhere"

Now it will work.

You have to use Jet OLEDB:Database Password not pwd key word.

Cheers

Narayanan
0
 

Author Comment

by:dj_humpyg
ID: 8218746
Thanks rafsalman,

I managed to tweak what you supplied and from what I had obtained from the web. Also thanks to n_narayanan for the response. The code I got in the end was alittle different to both responses by thank you. Code I've now got (that works) is posted below.

----------------------------------------
Dim myConn As New ADODB.Connection
Dim myRS As New ADODB.Recordset

myConn.Open "dsn=dsnhere; uid=useridhere;pwd=passwordhere;"

Set myRS = myConn.Execute("SELECT.....")
----------------------------------------

I did originally specifiy something like:

myConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security " & _
         "Info=False;Data Source=c:\test.mdb;"

but in the end I didn't need to.

Thanks, and sorry about the refreshing of this page.
0
 

Author Comment

by:dj_humpyg
ID: 8218756
Quick to post, and I didnt specify it was an ODBC connection, so code needed tweaking.
0
 
LVL 1

Expert Comment

by:rafsalman
ID: 8218801
Great glad you got it to work - enjoy the success!
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 7 hours left to enroll

616 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