odbc| Data | Data source you can see it. Using the Windows Control Panel tool to establish an ODBC data source is to establish the corresponding value in the registry.
The following function can establish an ODBC data source for SQL Server! You can observe the registry yourself, modify a part of the value!
<summary>
Registering an ODBC data source
</summary>
<param name= "DSNname" >odbc the data source name, which is consistent with the SQL Server database name </param>
<param name= "ServerName" >sql Server database server name </param>
<returns> return Success </returns>
private bool Regodbc (string dsnname,string ServerName)
{
Try
{
In Hkey_local_machine\software\odbc\odbc. INI to create a subkey and corresponding value
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");
In Hkey_local_machine\software\odbc\odbc. Add a string key value to the 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;
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.