We are SQL Server Experts. Call Us TODAY! +17738095456 or email us at sales@itimpact.com
  • The Team
  • Our Services
    • Dashboards Developers
    • Microsoft SQL Server
    • Microsoft SQL Server hosting for Access
    • SQL Server Integration Services (SSIS)
    • SQL Server Reporting Services (SSRS)
    • SQL Server Data Quality Services (DQS)
    • Microsoft Access
    • Microsoft VB.Net
    • Cross Functional / Business Unit Integration
    • Financial Statement Consolidation
    • Website Design
  • Case Studies
    • Automatic Reporting for Security Services Firm
    • Amazon API Integration with Access
    • Custom Quoting and Proposal Solution
    • Data Quality Analysis for Government Program
    • New Claim System Reduces Processing Time
    • Pipe Tracking Software
    • Product Search Analysis
    • Safety Training, Incident and Accident Tracking Tool
    • Union Dues and Membership Management System
  • Blog
  • Contact
  • The Team
  • Our Services
    • Dashboards Developers
    • Microsoft SQL Server
    • Microsoft SQL Server hosting for Access
    • SQL Server Integration Services (SSIS)
    • SQL Server Reporting Services (SSRS)
    • SQL Server Data Quality Services (DQS)
    • Microsoft Access
    • Microsoft VB.Net
    • Cross Functional / Business Unit Integration
    • Financial Statement Consolidation
    • Website Design
  • Case Studies
    • Automatic Reporting for Security Services Firm
    • Amazon API Integration with Access
    • Custom Quoting and Proposal Solution
    • Data Quality Analysis for Government Program
    • New Claim System Reduces Processing Time
    • Pipe Tracking Software
    • Product Search Analysis
    • Safety Training, Incident and Accident Tracking Tool
    • Union Dues and Membership Management System
  • Blog
  • Contact
Toggle panel Social icons
SQL Server

Securing your ADO connections

A while ago, I wrote about securing the ODBC connections which was published on Access team’s blog. Also, Juan recently wrote about the alternate method of deleting/recreating linked tables in a four part article. But what about ADO connections? A typical approach for creating an ADO connection may look like this:

(simplified for example)

Public Con As ADODB.Connection

Public Sub OpenMyConnection() As Boolean
   Set Con = New ADODB.Connection
   Con.ConnectionString = _
     "Provider=sqloledb;Server=myserver.com;Database=mydatabase" & _
     "...." 'additional parameters as appropriate
   Con.Open
   'Note the changes made after Con.Open to the Connection String
   Debug.Print Con.ConnectionString
End Sub

We may supply the connection parameters to the ConnectionString property and whenever we do use SQL Server authenication, the username and password are also embedded in the ConnectionString property. The biggest problem with this is that once the connection is opened, those username and password are still easily accessible through even unrelated objects. To provide the example, we’ll use a recordset to obtain that information:

Public Sub ShowIt()
  Dim rs As ADODB.Recordset

  Set rs = New ADODB.Recordset
  rs.Open "SELECT 1 FROM dbo.MyTable", Con
  Debug.Print rs.ActiveConnection.ConnectionString
  rs.Close
  Set rs = Nothing
End Sub

So though we reused an ADODB connection and didn’t refer the original connection string, it was still implicitly available once we assigned the existing ADODB connection object to the recordset and could read the full connection string, with user id and password included. That’s a big security hole. The connection string may have had changed slightly from what you had put in, displaying additional information such as using more specific version of driver, additional parameters of the connection but what really matter is that user id and password is still in there.

Don’t persist the sensitive information

Fortunately, this is easy to rectify. Simply add this parameter to all your ADO connections:

  con.ConnectionString = _
    "Persist Security Info=false;" & _
    "Provider=sqloledb;Server=myserver.com;Database=mydatabase;" & _
    "...." 'additional parameters as appropriate

The effect of including “Persist Security Info=false” instructs ADO library to discard the user id and password from the connection string after the connection has been successfully opened. Thus, in the OpenMyConnection, the user id and password is embedded in the connection string but only until the line “Con.Open”. Afterward, the connection string will not display that information so it cannot be extracted later.

Thus, using “Persist Security Info=false;” for all your ADO objects in conjunction with the suggestions provided for managing linked objects and ODBC objects, you can achieve a database application that won’t store the sensitive authentication information anywhere.

But what about connection string being stored?

I definitely would not recommend storing the user id and password in the database application. A syntax like this:

Const strConnectionString = _
 "Provider=sqloledb;Server=myserver.com;Database=mydatabase;" & _
 "uid=foo;pwd=bar;"

is vulnerable because it can be read, even when you use a MDE/ACCDE file, store it as a private variable in a private module. If at all possible, have the user log in with a dedicated login so it does not have to be stored. However, that is not always practical, and sometime you may use a shared SQL login. In the latter case, borrowing Patrick Wood’s approach may be more preferable. He discusses using a function to build the authentication information. This way, the connection string isn’t directly stored and must be constructed, which makes it a bit harder to extract.

No Comments on “Securing your ADO connections”

  1. Giorgio Rovelli June 4, 2012 at 3:28 pm

    Hi Ben, when you use Patrick’s procedure to produce passwords, how do you use it in the procedure arguments, as Patrick says? And since it’s not advisable to store the password, how do you retrieve it once it’s created?

    Reply
    1. Ben Clothier Post authorJune 4, 2012 at 3:54 pm

      You’d probably do this:

      con.ConnectionString = PartColor(““)

      As for storing the password – that’s basically why I recommend against it because in the end of day, it’s security through obscurity. The idea is that you wouldn’t have a constant or function that’s obviously named “strPassword” or “MyConnectionString” but rather that you have a function named “PartColor” and a constant named say, “strSerialNumber”. By making them apparently unrelated, it’s not as obvious how you would obtain the password and may just frustrate enough to protect the application. Of course, a more dedicated & savvy hacker can simply work around that problem.

      You can further obscure the connection string password by using an algorithm that pulls together data from random bits of application (e.g. form’s name, lastupdated property of unused local table, etc.) then hashing it so you don’t have to hardcode it anywhere inside the VBA module or even on form properties. (Note: Tag property is perhaps even worse place since it can be not only read but also edited).

      I hope that helps.

      Reply
  2. Jude June 28, 2013 at 8:41 pm

    Wonderful goods from you, man. I’ve understand your stuff previous to and you are just extremely wonderful. I really like what you have acquired here, certainly like what you are saying and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I cant wait to read far more from you. This is actually a tremendous website.

    Reply

Click here to cancel reply.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

XHTML: You can use these tags <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Recent Posts

  • 23 Jan. 2019 7 essential SQL skills that can help you command a higher paycheck

  • 18 Jan. 2018 Quick Guide on Importing Data from SQL Server (or SQL Azure) to Cosmos DB

  • 10 Jan. 2018 Top 7 Questions about Basic Availability Groups

  • 04 Jan. 2018 An introduction to mssql-cli, a command-line client for SQL Server

  • Share and work together on the intranet with SharePoint Team Sites

ITImpact

About IT Impact, Inc.

IT Impact, Inc.

IT Impact, Inc. is a minority-owned software company specializing in custom software solutions. We work with SQL Server, Microsoft Access, web applications, and much more.

Our staff is top of the line and includes two Microsoft MVPs!

Twitter

Tweets by @ITImpactInc

Facebook

© ITImpact. Webdesign by GreatCustomWebsites.com