A Common ODBC Connection Strings works for SQL Server 2005+ - sql-server

I am using CDatabase in VC2008 to connect to SQL Server via ODBC.
I want to use a common connection string that can work for SQL Sever 2005 and all higher versions.
I check https://www.connectionstrings.com/microsoft-sql-server-odbc-driver/ and see there are many different kinds of connection strings.
Whether I should use:
Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;
or
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
Pwd=myPassword;
Update:
Based on my test, using Driver={SQL Server} or Driver={SQL Server Native Client 10.0} can both connect to SQL Server 2008. I guess the former will works for all SQL Server versions, but the latter will only works for SQL Server 2008. Please confirm my guess.

Both driver will connect to Sql Server.But purpose of both drivers are different.
Driver={SQL Server} :
It is called Windows Data Access Components (WDAC).
It do not support new feature of Sql server 2005+ like xml data type,Multiple active result sets (MARS), user-defined data types (UDT), query notifications etc.
It support only Read Committed transaction isolation.
Driver={SQL Native Client}
This driver is suitable for application that need to take advantage of new feature of Sql server 2005+.
It support both Read Committed transaction and snapshot transaction isolation level.
System.Data.SQLClient
SQLClient is optimize for .NET and database Sql server 2000+.
It give maximum performance.
So if your application is new or existing then use SQL Native Client.It can access all feature of connected version of Sql server 2005,2008 etc.
ODBC :Use ODBC when application is connected to multiple database or it is expected that database may change.DAL code is written in such a manner it will work for any database.
Suggested Reading
Common Connection : I don't think there can be any common connection.Suppose in my system SQL server native client 10 is install then I know that I cannot connect to Sql server 2016 + .SQL server native client 10 will work for Sql Server 2016 and below.
Of course by programming we can make dynamic connection string which will accept driver as parameter etc.
To connect to higher version ,s I will hv to upgrade my driver and do minor change in connection string.Or if you don't want to touch code then Use DSN.
Yes I forgot, Driver={SQL Server Native Client} it can connect to Sql Srver 2005 only.if you try to connect to higher version then it will throw error.

Related

Linking 2010 SQL Native Client 11.0 to SQL Server 2000 for report

I have a legacy system at one of our locations in the US. We currently have a reporting system using SQL Server Report Builder on a central server running SQL Server 2014 using the native client SQL 11.0. I need to build a report using two different remote systems. I have setup linked servers before, but the current issue is that I am trying to setup a linked server to a 2000 server. When I try to make the connection to it it returns an error that native client 11 cannot communicate with SQL Server 2000. I have not found any reliable work around for this, and am trying to see if there is a resolution or solution that can be used.
I was also wondering if maybe a possibility is to create a ODBC connection the SQL server. Then create a linked server to the ODBC, in return that is older version.
ODBC to SQL Server 2000
SQL client 11 to ODBC
Is this possible, or a very poor way to handle this? Thanks in advance!

Differences Between Drivers for ODBC Drivers

I was setting up the System DSN (64 bit) for my database in SQL server 2016 with Windows 10 64 bit pro. While I was asked to choose the driver to set up a data source, there are the following selections:
ODBC Driver 13 for SQL Server
SQL Server
SQL Server Native Client 11.0
SQL Server Native Client RDA 11.0
It seemed I can set up the data source with all of these drivers. Then which one should I choose in terms of speed and efficiency? What's the difference between them?
Thanks,
Jason
ODBC Driver for SQL Server
ODBC is the primary native data access API for applications written in C,C++, PHP, Python and others for connecting to SQL Server.
It's widely used in data integration scenarios.
Also, it's preferred if you are developing application on Windows and deploying it to Linux .
SQL Server
The full name of SQL Server Driver is SQL Server ODBC Driver. It’s an old driver since sql 2000.
You can use it to connect to SQL Server 2016, but you will not be able to access new features and functionality of SQL Server 2016
SQL Server Native Client
SQL Server Native Client is containing both the SQL OLE DB provider and SQL ODBC driver to support native connectivity to SQL Server and support all features of sql server 2016.
It's the best in windows environment
SQL Server Native Client RDA
Remote data access (RDA) in Microsoft SQL Server Compact 3.5 lets an application access data from a remote SQL Server database table.
It can also store, read, and update that data in SQL Server Compact 3.5, and then update the original SQL Server table.
RDA will be removed in the future release, so avoid using it.
So choose sql driver based on the criteria above.
Microsoft ODBC Driver for SQL Server (MSODBCSQL)
This driver was announced in 2013 as the successor to SQL Server Native Client. It is installed with recent SQL Server versions. There are standalone installers for clients. Driver history for Microsoft SQL Server recommends this driver in preference to "SQL Server" and "SQL Server Native Client" for ODBC. Added features over "SQL Server Native Client": driver-aware connection pooling, connection resiliency, asynchronous execution (polling), support for Always Encrypted, recent SQL Server compatibility (including Azure SQL), and more supported operating systems (including Linux and macOS). You can follow current development on the SQL Server Blog (with previous posts on the SQLNCli team blog).
Driver={ODBC Driver XX for SQL Server} (XX replaced by driver version. See System Requirements, Installation, and Driver Files.)
SQL Server Native Client (SQLNCLI)
Introduced with SQL Server 2005 and ships with SQL Server (also installable via sqlncli.msi from SQL Server feature packs). Added features over "SQL Server": Multiple active result sets (MARS), user-defined data types (UDT), query notifications, snapshot isolation, and XML data type support. The version for SQL Server 2008 also added support for the new date and time types.
Driver={SQL Server Native Client} (SQL Server 2005)
Driver={SQL Server Native Client 10.0} (SQL Server 2008)
Driver={SQL Server Native Client 11.0} (SQL Server 2012 and later)
SQL Server Native Client RDA
Remote Data Access (RDA) is a SQL Server Compact feature which "lets an application access data from a remote SQL Server database table." I can't find much documentation, but it appears this driver was intended to support replication scenarios with Compact Edition.
SQL Server (SQLSRV32)
Included in Microsoft Data Access Components (MDAC) (now called Windows Data Access Components (WDAC)). This driver is available by default on Windows (since 98 and NT 4.0).
Driver={SQL Server}
To check which drivers you have installed, fire up an powershell (32/64 bit - depending which driver architecture you want to use) and run
OLEDB
(New-Object System.Data.OleDb.OleDbEnumerator).GetElements() | select SOURCES_NAME, SOURCES_DESCRIPTION
ODBC
Get-OdbcDriver | select Name,Platform
Overview
https://learn.microsoft.com/en-us/sql/connect/connect-history#odbc
There are three distinct generations of Microsoft ODBC drivers for SQL Server.
The first "SQL Server" ODBC driver still ships as part of Windows Data Access Components. It is not recommended to use this driver for new development.
Starting in SQL Server 2005, the SQL "Server Native Client 10.x/11.x/12.x" includes an ODBC interface and is the ODBC driver that shipped with SQL Server 2005 through SQL Server 2012. It is not recommended to use this driver for new development.
After SQL Server 2012, the Microsoft ODBC Driver for SQL Server is the driver that is updated with the most recent server features going forward.
SQL Server
It's the old one from the MDAC-package (https://support.microsoft.com/en-us/help/899456) which now (since XP/2003) comes with the Windows-OS.
https://learn.microsoft.com/en-us/sql/connect/connect-history#mdacwdac-releases
https://learn.microsoft.com/en-us/sql/relational-databases/native-client/applications/updating-an-application-to-sql-server-native-client-from-mdac
...starting with Windows Vista, the data access components are now called Windows Data Access Components, or Windows DAC). Although both provide native data access to SQL Server databases, SQL Server Native Client has been specifically designed to expose the new features of SQL Server 2005 (9.x), while at the same time maintaining backward compatibility with earlier versions.
SQL Server Native Client
https://learn.microsoft.com/en-us/sql/connect/connect-history#odbc
SQL Server Native Client is a stand-alone library that is used for both OLE DB and ODBC. SQL Server Native Client (often abbreviated SNAC) was included in SQL Server 2005 through 2012. SQL Server Native Client can be used for applications that need to take advantage of new features introduced in SQL Server 2005 through SQL Server 2012. (Microsoft/Windows Data Access Components are not updated for these new features in SQL Server.) For new features beyond SQL Server 2012, SQL Server Native Client will not be updated. Switch to the Microsoft ODBC Driver for SQL Server or the Microsoft OLE DB Driver for SQL Server if you want to take advantage of new SQL Server features going forward.
SQL Server Native Client RDA
Came with .NET Compact Framework 3.5
ODBC Driver for SQL Server
https://learn.microsoft.com/en-us/sql/connect/connect-history#odbc
After SQL Server 2012, the primary ODBC driver for SQL Server has been developed and released as the Microsoft ODBC Driver for SQL Server.
MSOLEDBSQL - Microsoft OLE DB Driver for SQL Server
This driver has been deprecated and later undeprecated:
https://learn.microsoft.com/en-us/sql/connect/oledb/oledb-driver-for-sql-server#3-microsoft-ole-db-driver-for-sql-server-msoledbsql
The new OLE DB provider is called the Microsoft OLE DB Driver for SQL Server (MSOLEDBSQL). The new provider will be updated with the most recent server features going forward. To use the new Microsoft OLE DB Driver for SQL Server in existing applications, you should plan to convert your connection strings from SQLOLEDB or SQLNCLI, to MSOLEDBSQL.
https://blogs.msdn.microsoft.com/sqlnativeclient/2018/03/30/released-microsoft-ole-db-driver-for-sql-server/
Summary
Try to use the future proof drivers:
ODBC - https://learn.microsoft.com/en-us/sql/connect/odbc/bug-fixes
OLEDB - https://learn.microsoft.com/en-us/sql/connect/oledb/release-notes-for-oledb-driver-for-sql-server
SQL Server Native client vs .NET Framework Data Provider for ODBC
It seems that for last version for SQL Server Native client, the Microsoft® SQL Server® 2012 Native Client also named as SQL Server native client 11.0.
Doesn’t support new feature in SQL Server 2014 or later
Note that SNAC 11 does not support features released with SQL Server
2014 and SQL Server 2016 that were not available as part of SQL Server
2012, such as Transparent Network IP Resolution, Always Encrypted,
Azure AD Authentication, Bulk Copy and Table Value Parameters.
https://blogs.msdn.microsoft.com/sqlreleaseservices/snac-lifecycle-explained/
You have to use Microsoft® ODBC Driver 11 or 13 for SQL Server to enjoy new feature in SQL Server 2014 or later
As mentioned earlier in this post, the later version of the ODBC driver (13 and after) give you access to the more advanced features available in SQL Server 2014, 2016, etc.
However, there are conflicting Microsoft posts on whether the ODBC Version 17 driver supports SQL Server 2012 or not.
This link says you have to use ODBC 13 for SQL Server 2012:
SQL Server Driver Versions
However, if you look at the download for the ODBC Version 17, it indicates it support for SQL Server 2012 (and older versions of SQL Server).
Microsoft® ODBC Driver 17 for SQL Server® - Windows, Linux, & macOS
So perhaps the ODBC Version 17 driver is (at least) backwards compatible with older versions of SQL Server.
Hope this helps!
Jon

How to connect to a SQL Server database from local pc?

I am a Crystal Reports developer and I have always been working with Oracle database and this is my first time with SQL Server.
This is what I have been desperately searching for.
From my local PC, I want to connect to a SQL Server database which is on a database server.
I am aware that I need a 'SQL Server Native Client'. And I am also aware that I need to use 'sql server management studio' so that I can view the tables and writes queries instead of using a tool like TOAD.
My questions are:
Can I use 'Microsoft SQL Server Management Studio Express' from my local PC to connect to a SQL Server 2005 Database in a database server?
If I install 'Microsoft SQL Server Management Studio Express' do I still need to install a 'SQL Server Native Client'?
Thanks,
rivi
Can I use 'Microsoft SQL Server Management Studio Express' from my local PC to connect to a SQL SERVER 2005 Database in a database server?
Yes.
If I install 'Microsoft SQL Server Management Studio Express' do I still need to install a 'SQL Server Native Client'?
If you want to connect to the database from your application you will need it installed. It should be installed as part of the SSMS install.
Answer 1:
SQL Server Management Studio can be used to manage either local or remote SQL database server.
If you installed SQL Server Express, the default instance will be SQLExpress. To connect it locally using Windows Credential, just type .\SQLExpress or yourmachinename\SQLExpress in the server name textbox.
If you host the SQL Server on a remote server, you must use the credential given by the authority hosting your SQL Server. It is easy, ask your admin for the details.
Answer 2:
See this for the details
I copy and paste the important notes from the link above here:
When deciding whether to use SQL Server Native Client as the data access technology of your application, you should consider several factors.
For new applications, if you're using a managed programming language such as Microsoft Visual C# or Visual Basic, and you need to access the new features in SQL Server, you should use the .NET Framework Data Provider for SQL Server, which is part of the .NET Framework.
If you are developing a COM-based application and need to access the new features introduced in SQL Server, you should use SQL Server Native Client. If you don't need access to the new features of SQL Server, you can continue to use Microsoft Data Access Components (MDAC).
For existing OLE DB and ODBC applications, the primary issue is whether you need to access the new features of SQL Server. If you have a mature application that does not need the new features of SQL Server, you can continue to use MDAC. But if you do need to access those new features, such as the new xml Data Type, you should use SQL Server Native Client.
Both SQL Server Native Client and MDAC support read committed transaction isolation using row versioning, but only SQL Server Native Client supports snapshot transaction isolation. (In programming terms, read commited transaction isolation with row versioning is the same as Read-Committed transaction.) For more information, see Choosing Row Versioning-based Isolation Levels.
For information about the differences between SQL Server Native Client and MDAC, see Updating an Application to SQL Server Native Client from MDAC.

Crystal Reports, which OLEDB provider to use for SQL Server

When designing a new Crystal Report you have to create a new database connection. I have selected OLE DB (ADO) as the 'driver' as it made more sense than DAO,RDO or the other options for my requirements.
I need to execute an SQL Server 2005/2008 stored procedure on a remote server and show the results in Crystal Reports on a .NET client.
Selecting OLE DB, presents me with further options to select the correct provider, some of which are:
Microsoft OLEDB provider for ODBC drivers
Microsoft OLEDB provider for SQL Server
SQL Native Client
SQL Server Native Client 10.0
Which on is the best to use?
I don't want to use the ODBC drivers, for various disadvantages (setting up ODBC definitions and maybe slower).
Not sure how the OLEDB provider for SQL Server compares with the native client
The native client forced me to run the native client setup on each desktop. It also seems that there is different version for each version of SQL Server.
Initially I thought the native client is the logical choice for compatibility and performance but deployment seems to be an issue (unless I am doing something wrong)
What is the best connection driver/provider combination to use here?
I would go with the Microsoft OLEDB provider for SQL Server. If you use the native client, you will need to distribute it with your applications.
This article talks about the native client in detail: http://blog.flex2sql.com/index.php/2009/02/how-and-when-to-use-sql-server-native-client/

Sql Server 2005, Xml types, and ODBC?

Can a Sql 2005 database that uses the xml type be accessed with ODBC?
I believe XML datatypes will be, pretty much, handled as character data types...
Certainly, the OpenLink ODBC driver returns XML data types, locally, as SQL_LONGVARCHAR.
Not sure if this is true for all ODBC drivers connecting to SQL Server 2005, but DataDirect does claim to support pretty much all SQL Server 2005 and even most of the new SQL Server 2008 features. See their listing here.
Ah, and here's Microsoft comment on it:
If you are developing a COM-based application and need to access the new features of SQL Server 2005, you should use SQL Native Client. If you don't need access to the new features of SQL Server 2005, you can continue to use Microsoft Data Access Components (MDAC).
So I guess, if you use the SQL Native Client ODBC driver, you should be able to use the XML data type.
Marc
This's supported in the sql server's native client odbc driver with the new SQL_SS_XML type.
http://msdn.microsoft.com/en-US/library/ms131375%28v=SQL.90%29.aspx

Resources