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

SQL Server Connections Strings for SQL Server

Readers of my blog know how passionate I am connecting Access to SQL Server, it’s one of my favorite ways to deploy my solutions. Today I’m going to talk about the different methods and connection strings you can use to connect between Access and SQL Server.

Two Drivers Available
You have two sets of drivers available when connecting: use the standard driver that ships with every Windows station and SQL Server Native Client. The latter is recommended since I’ve personally seen better speeds connecting with SQL using it. You can download the client here, just navigate to the section called “Microsoft SQL Server 2008 Native Client”. Make sure you pick the version compatible with your operating system.

ODBC Connection
The easiest way to connect with SQL would be creating a DSN on the local machine and use it to link SQL tables in Access. This is also the least recommended, since you have to repeat the process for every computer using your Access with SQL database. You can also distribute a DSN file with your application as well. If you installed SQL Server Native Client then you will see both the old SQL Server driver and the new one as an option when creating the DSN. If you decide to use SQL Server Native client you will also need to install it on the local machine when installing your solution.

DSNless Connections
This is the preferred method in connecting with SQL, there is no need to create a DSN on each machine, thus avoiding all the hassles in visiting each machine when you’re ready to roll out the database. When creating DSNless or connecting with ADODB to SQL, you have four options: Old vs new SQL drivers and Integrated Security or SQL Server logins.

Integrated security means you are using the user’s windows credentials when connecting with SQL and is the preferred method in connecting. It allows you to leverage domain credentials and security to easily manage user rights in your application.

The other connection method is using SQL Server security. It’s the only method available if the SQL Server is on the Internet and your users are connecting from the road. If you go this route you will need to pass along the user name and password in order to validate your connection.

Here is an example of Integrated Security with the Windows standard SQL server driver:

stConnect = “ODBC;DRIVER=SQL Server;SERVER=” & stServer & “;DATABASE=” & stDatabase &  _ “;Trusted_Connection=Yes”

and here’s one using SQL Server security:

stConnect = “ODBC;DRIVER=SQL Server;SERVER=” & stServer & “;DATABASE=” & stDatabase & “;UID=” & stUsername & “;PWD=” & stPassword

Here is an example using SQL Server Native Client 10.0:

stConnect = “ODBC;DRIVER=SQL Server Native Client 10.0;SERVER=” & stServer & “;DATABASE=” & stDatabase & “;UID=” & stUsername & “;PWD=” & stPassword

 

Bypass ODBC in your code
You should bypass the ODBC layer altogether when connecting to SQL Sever by using a connection string similar to this one in your code:

stConnect = “Provider=SQLOLEDB;Data Source=” & stServer & “;Initial Catalog=” & stDatabase & “;Integrated Security=SSPI;”

Or if you’re using native client:

stConnect = “Provider=SQLNCLI10;Data Source=” & stServer & “;Initial Catalog=” & stDatabase & “;Integrated Security=SSPI;”

You can see additional examples here.

Don’t forget the instance name!
When connecting to a SQL Server Express database, you must include the instance name along with the server name. For example, the default instance name when installing Express is “SQLExpress”, if you’re connecting to a server called “DEVServer” than the server portion of your connection string should be: “DEVServerSQLExpress”

 

 

No Comments on “SQL Server Connections Strings for SQL Server”

  1. Pingback: Using ADODB recordsets and command objects in Access | Access Help and Tips by AccessExperts.net

  2. Dave January 6, 2012 at 4:05 am

    Hi Juan,

    I recently came across an odd thing that I can’t explain. If I use DRIVER={SQL Server}; in place or DRIVER=SQL Server; in my connections string my re-linking takes twice as long to complete. Can you explain why this is?

    Thanks
    Dave

    Reply
    1. Juan Soto Post authorJanuary 7, 2012 at 10:43 pm

      Dave,

      Thanks for sharing! I have no idea why it would be faster but will come back here once I find out and let you know.

      Thanks
      Juan

      Reply
  3. naresh February 1, 2012 at 10:02 am

    testing

    Reply
  4. Rx April 4, 2012 at 2:54 am

    One of the best DSNLess examples out there. For my Access 2010 to SQL 2008, I noticed that SQL Server Native Client 10 converted all my date /time fields perfectlly when useing it manually as part of the ODBC connection.
    Building code for my tables DNSLess to connect to a SQL Server 2008 R2 on a virutal server. What would the connection string be any different than SQL Express?

    Reply
    1. Juan Soto Post authorApril 4, 2012 at 3:19 am

      With SQL Express you need to include the server instance, for example, the default instance is SQLExpress so that the proper way to connect would be the server IP followed by the instance and the port if it’s different than the standard port:
      SQLServerIPSQLExpress,1433

      Reply
  5. Rx April 4, 2012 at 2:58 am

    Integrated Security=SSPI;” Just noticed – both of your examples are the same. I need the string for SQL Server Security. My front-end will connect to SQL Server and be distributed via Citrix. It helps with security, lowers bandwidth and we even have Apple users that are happy with MS Access.

    Reply
    1. Juan Soto Post authorApril 4, 2012 at 3:21 am

      The first two examples demonstrate using integrated security and SQL Server security. The latter two demonstrate using the native SQL client vs. the standard ODBC driver that comes with Windows.

      Reply
  6. Sonny April 26, 2012 at 7:28 pm

    Thanks for Great Article Juan
    I now have access2007 connected to an sqlserver.
    I’m completley new to ADO but have a rudimentary knowledge of SQL/VBA/DAO
    It took a bit of fiddling around and trial and error but essentially took me about 3 hours
    to scale up my Access application from an accessFE & BE to an access FE/SQLserver backend
    and be able to connect to it

    the global variables and the OpenMyRecordset and ExecuteMyCommand
    will be a big help to convert my functions

    Cheers

    Reply
    1. Juan Soto Post authorApril 26, 2012 at 7:35 pm

      Glad to hear!

      Please consider signing up as a subscriber to get the latest posts via email.

      Regards
      Juan

      Reply
  7. http://tinyurl.com/gmairoe19421 April 14, 2013 at 3:05 pm

    I truly have a tendency to go along with every aspect that was
    in fact posted within “SQL Server Connection
    Strings for Microsoft Access | accessexperts.com”. I am grateful for pretty much all the actual information.
    I appreciate it-Mariel

    Reply
  8. Jose October 9, 2013 at 12:23 am

    Juan,

    I am new to application development so please sorry for the ignorance. I built a MS Access front end with a SQL Server Backend. However, I used the DNS approach not knowing that each user machine will need a DNS created. I see the DNSless example above but I am not sure how to implement into my solution. Where do I write the code? Can I write it once then my application will have access to all SQL Server tables? Thanks in advance for you help.

    Reply
    1. Ben Clothier October 9, 2013 at 9:08 pm

      Jose,

      Generally, you’d use a standard module and add a procedure that you would call at startup to create the connection.

      To see an example of such thing, have a look at this article. I hope that helps.

      Reply
  9. Suanne Varming June 12, 2014 at 8:04 pm

    Hi

    Faulty link on your page:
    http://www.microsoft.com/library/errorpages/smarterror.aspx

    I have a question too:
    I have upsized from access 2010 to sql server.

    The sql statements which previously worked with CurrentDb do not work any more.

    What do I need to do in order to be able to execute sql statements against sql server ?

    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