A SQL Server driver handles the conversation between your application and the database. Choosing the right driver is only the beginning; authentication, encryption, and connection lifetime also need explicit decisions.

Choose the Driver for the Runtime
Java applications commonly use Microsoft's JDBC Driver for SQL Server. Python can use pyodbc with the Microsoft ODBC Driver installed on Windows. Modern .NET applications can use Microsoft.Data.SqlClient.
Check the supported runtime and operating-system requirements for the selected release. Record the driver version in the application's deployment information. The server version alone does not describe how the client connects.
For Python, distinguish the Python package from the native ODBC driver. Installing one does not necessarily install the other. Also check application bitness and the installed driver's architecture when diagnosing a Windows deployment.
Make Connection Settings Explicit
Every connection needs the intended server endpoint, database, and authentication method. Add an application name that helps operations identify the workload. Store secrets through the application's approved configuration mechanism rather than embedding them in source files.
Example for SqlClient: Server=tcp:sql.example.test,1433;Database=AppDb;Integrated Security=true;Encrypt=true;TrustServerCertificate=false. Replace the endpoint and database with approved values. Windows integrated authentication uses the application's execution identity, which may differ from your desktop account.
An ODBC equivalent names Driver={ODBC Driver 18 for SQL Server} and uses Trusted_Connection=yes for Windows authentication. JDBC uses a jdbc:sqlserver:// endpoint with databaseName and encryption properties. Configure JDBC authentication according to its documented mode and any required Windows components.
SELECT @@SERVERNAME AS server_name, DB_NAME() AS database_name,
ORIGINAL_LOGIN() AS original_login,
USER_NAME() AS database_user,
APP_NAME() AS application_name,
@@SPID AS session_id;Execute this through the application connection being investigated. Running it in SSMS only describes the SSMS session. Compare the result with the intended deployment configuration.
Account for Encryption Defaults
ODBC Driver 18 changed the default Encrypt setting to yes. Microsoft JDBC Driver 10.2 changed its default to true. Microsoft.Data.SqlClient 4.0 also changed its default to true.
That means a driver upgrade can expose an existing certificate-trust problem. Use a trusted certificate and a connection name that matches it. Explicit settings make the deployment easier to review across driver upgrades.
TrustServerCertificate bypasses normal certificate validation when applicable. It is not a repair for the certificate's trust chain or name mismatch. Resolve the intended certificate configuration instead of hiding the error in production settings.
SELECT session_id, net_transport, protocol_type,
encrypt_option, auth_scheme
FROM sys.dm_exec_connections
WHERE session_id = @@SPID;This requires appropriate visibility into connection metadata. It shows the server's view of the current connection, including whether traffic is encrypted. It does not independently prove every client-side certificate-validation setting.
Handle Parameters and Transactions Deliberately
Pass values as parameters using the API supported by your driver. JDBC and pyodbc commonly use positional question-mark markers, while SqlClient uses named parameters. Match parameter types and sizes to the database contract.
Avoid constructing SQL by concatenating user values. Parameterization also helps preserve dates, decimals, and Unicode without fragile string formatting. Object names require a separate validated design because value parameters do not substitute SQL identifiers.
SELECT @@TRANCOUNT AS transaction_count,
XACT_STATE() AS transaction_state;
SELECT transaction_isolation_level
FROM sys.dm_exec_sessions
WHERE session_id = @@SPID;Use these checks when investigating unexpected transaction behavior through a connection. Understand the driver's autocommit behavior and the application's transaction boundaries. Close or roll back unfinished work on error paths.
Use Pooling Without Losing Ownership
Pooling reuses physical connections while application code opens and closes logical connections. SqlClient pools by connection configuration and related identity context. JDBC commonly uses an application or framework pool, while ODBC has its own pooling arrangements.
Release connections promptly through the runtime's normal cleanup pattern. Do not keep one shared connection open for unrelated concurrent requests. A leaked connection can exhaust a pool even while the database remains available.
Set connection and command timeouts according to different needs. Opening a connection and executing a statement are separate operations. Retrying a write also needs a design that prevents duplicate business effects.
Test the Complete Deployment
Test from the real runtime identity and network path. Include a parameterized read, a controlled transaction, and an intentional failure. Verify that cleanup returns the application to a usable state.
Record driver versions, approved connection settings, and diagnostic evidence without exposing secrets. Repeat the checks after driver upgrades. A dependable connection is one you can explain when the environment changes.
A connection string is not the whole connection, it is one part of a driver, identity, and lifetime contract.
This post was rewritten from scratch in September 2026. The original, published on 2009-01-27, was a short announcement about something that no longer exists. The address is the same, the subject is now something worth keeping.
Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.





3 Comments. Leave new
hello pianl dave!
i have this driver and i connected java and my ms sql server2008 but when i rty to querying the db from the java code for ex:
ResultSet rSet = state.executeQuery(“select * from dbo.categories”);
it wont display the fields or any data,
don’t know where is the problem,
Did you get any error?
no i didn’t get, i use netbeans 6.9.1
i don’t have any problem when i use embed database,
is it possible that the db have problem?