Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create odbc connection for SQL Server Using C# programmatic using win form

I Want to pass following data as parameter

1. ODBC Name
2. Description
3. Server Name
4. Change The Authorization for Sql server authentication
5. Provide Database User name and password
6. Change client configuration as Named Pipes

How to do this by using c# code ?

Please Help Me to solve this problem
thnks
Posted

1 solution

First of all, are you sure you have to connect through ODBC? can't you use SqlConnection objects?

If ODBC is required...

The ODBC profiles gets saved into registry folders (under HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources for machine shared profiles or HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources for user's private profiles) or as DSN files with any name and in any folder of your choice.

So, you can create and fill parameters for any of this containers (registry folder or DSN file) and then use SQLDriverConnect Function.
You can also call this function specifying all connection parameters you like (and avoiding the creation of any profile).

The easiest way to know how to create and fill the ODBC profile is creating them form the control panel application and then inspecting their contents looking into the registry or DSN file.

You can also have a look at ConfigDSN Function.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900