搞定C# 建立ODBC数据源
来源:互联网 发布:fastcam套料软件 编辑:程序博客网 时间:2024/04/29 11:46
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
下面的函数可以建立SQL Server的ODBC数据源!可以自己观察注册表,修改一部分值!
/// <summary>
/// 注册ODBC数据源
/// </summary>
/// <param name="DsnName">ODBC数据源名称,这里要与SQL Server数据库名保持一致</param>
/// <param name="ServerName">SQL Server数据库服务器名</param>
/// <returns>返回是否成功</returns>
private bool RegODBC(string DsnName,string ServerName)
{
try
{
//在HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.INI中创建一个子键和相应的值
Microsoft.Win32.RegistryKey regkey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software").OpenSubKey("ODBC").OpenSubKey("ODBC.INI",true).CreateSubKey(DsnName.Trim());
regkey.SetValue("DataBase",DsnName.Trim());
string strSystem32=Application.LocalUserAppDataPath.Substring(0,2);
strSystem32=strSystem32+@"/WINDOWS/System32/SQLSRV32.dll";
regkey.SetValue("Driver",strSystem32);
regkey.SetValue("Server",ServerName.Trim());
regkey.SetValue("Trusted_Connection","Yes");
//在HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.INI/ODBC Data Sources中增加一个字符串键值
regkey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software").OpenSubKey("ODBC").OpenSubKey("ODBC.INI",true).OpenSubKey("ODBC Data Sources",true);
regkey.SetValue(DsnName.Trim(),"SQL Server");
return true;
}
catch(Exception Err)
{
}
return false;
}
搞定C# 建立ODBC数据源';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
你观察就可以发现用windows控制面板的工具建立ODBC数据源就是在注册表中建立相应的值。下面的函数可以建立SQL Server的ODBC数据源!可以自己观察注册表,修改一部分值!
/// <summary>
/// 注册ODBC数据源
/// </summary>
/// <param name="DsnName">ODBC数据源名称,这里要与SQL Server数据库名保持一致</param>
/// <param name="ServerName">SQL Server数据库服务器名</param>
/// <returns>返回是否成功</returns>
private bool RegODBC(string DsnName,string ServerName)
{
try
{
//在HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.INI中创建一个子键和相应的值
Microsoft.Win32.RegistryKey regkey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software").OpenSubKey("ODBC").OpenSubKey("ODBC.INI",true).CreateSubKey(DsnName.Trim());
regkey.SetValue("DataBase",DsnName.Trim());
string strSystem32=Application.LocalUserAppDataPath.Substring(0,2);
strSystem32=strSystem32+@"/WINDOWS/System32/SQLSRV32.dll";
regkey.SetValue("Driver",strSystem32);
regkey.SetValue("Server",ServerName.Trim());
regkey.SetValue("Trusted_Connection","Yes");
//在HKEY_LOCAL_MACHINE/Software/ODBC/ODBC.INI/ODBC Data Sources中增加一个字符串键值
regkey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey("software").OpenSubKey("ODBC").OpenSubKey("ODBC.INI",true).OpenSubKey("ODBC Data Sources",true);
regkey.SetValue(DsnName.Trim(),"SQL Server");
return true;
}
catch(Exception Err)
{
}
return false;
}
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 搞定C# 建立ODBC数据源
- 如何建立ODBC数据源
- BCB 建立ODBC数据源
- vfp建立ODBC数据源
- 如何建立ODBC数据源
- VC动态建立ODBC数据源
- 建立 ODBC Mysql 远程数据源
- Asp.Net建立ODBC数据源连接
- Win7下怎么建立ODBC数据源
- 部分数据库中ODBC数据源的建立
- c#通过ODBC数据源连接Mysql数据库
- ODBC数据源 ~~
- ODBC数据源
- ODBC数据源
- ODBC数据源
- odbc数据源
- 在Delphi里调用API函数动态建立ODBC数据源。
- C#连接 ODBC 数据源时的默认驱动程序问题
- 获得结果
- 动态的管理ASP.NET DataGrid数据列
- 一个例子
- VB.NET中的对象序列
- MySQL中文参考手册6(MySQL与标准的兼容性) 对ANSI SQ
- 搞定C# 建立ODBC数据源
- 设计模式C#描述——抽象工厂模式
- MySQL中文参考手册5(安装MySQL上)
- C# sqlserver2000
- 把vfp表中的数据导入指定的excel文件中
- Win2000 Server安全入门
- 如何查看什么时间有哪些数据库对象结构被修改过
- ASP.NET里的事务处理
- 转:Visual Basic.NET快速开发MIS系统(1)