如何使用C#创建odbc驱动器 [英] how to create odbc drive using C#

查看:156
本文介绍了如何使用C#创建odbc驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Win形式使用C#编程为SQL Server创建odbc连接

我想传递以下数据作为参数

1. ODBC名称
2.说明
3.服务器名称
4.更改Sql Server身份验证的授权
5.提供数据库用户名和密码
6.将客户端配置更改为命名管道"

如何使用C#代码执行此操作?

请帮助我解决此问题
thnks

解决方案

首先,确定要通过ODBC连接吗?您不能使用SqlConnection对象吗?

如果需要ODBC ...

ODBC配置文件被保存到注册表文件夹中(用于计算机共享配置文件的 HKEY_LOCAL_MACHINE \ SOFTWARE \ ODBC \ ODBC.INI \ ODBC数据源下,或 HKEY_CURRENT_USER \ SOFTWARE \ ODBC \ ODBC.INI \ ODBC数据下用户的个人资料的来源),也可以是DSN文件(具有任何名称,可以位于您选择的任何文件夹中).

因此,您可以为任何一个容器(注册表文件夹或DSN文件)创建并填充参数,然后使用 ConfigDSN函数. blockquote>

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

解决方案

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.


这篇关于如何使用C#创建odbc驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆