?
Solved

Connection to ODBC - hardcode password

Posted on 2003-03-27
11
Medium Priority
?
934 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

764 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