September 2003
Intermediate to advanced
624 pages
14h 27m
English
You need a list of the OLE DB providers installed on the machine running your code.
Use a SQL Server extended stored procedure or search the registry.
In the first case, the sample code executes the extended stored
procedure xp_enum_oledb_providers. The result set
containing the installed OLE DB providers is displayed.
In the second case, the sample code uses the
Microsoft.Win32.Registry class to examine the
registry, identify OLE DB provider subkeys, and retrieve and display
the OLE DB provider names from these subkeys.
The C# code is shown in Example 10-13.
Example 10-13. File: OleDbProvidersForm.cs
// Namespaces, variables, and constants
using System;
using System.Configuration;
using System.Text;
using Microsoft.Win32;
using System.Data;
using System.Data.SqlClient;
// . . .
// SQL Server extended stored procedure StringBuilder result = new StringBuilder("Using SQL Server xp_enum_oledb_providers." + Environment.NewLine); int count = 0; SqlConnection conn = new SqlConnection( ConfigurationSettings.AppSettings["Sql_Master_ConnectString"]); // Create a command to execute the extended stored procedure to // retrieve OLE DB providers. SqlCommand cmd = new SqlCommand("xp_enum_oledb_providers", conn); cmd.CommandType = CommandType.StoredProcedure; // Create the DataReader. conn.Open( ); SqlDataReader rdr = cmd.ExecuteReader( ); // Iterate through the OLE DB providers in the DataReader. while(rdr.Read( )) { result.Append(++count + ...Read now
Unlock full access