Exemplo n.º 1
0
		/// <summary>
		/// Returns the ODBC Drivers installed in the local machine.
		/// </summary>
		/// <returns></returns>
		public static OdbcDriver[] GetOdbcDrivers()
		{
			ArrayList driversList = new ArrayList();
			OdbcDriver[] odbcDrivers = null;

			// Get the key for
			// "KHEY_LOCAL_MACHINE\\SOFTWARE\\ODBC\\ODBCINST.INI\\ODBC Drivers\\"
			// (ODBC_DRIVERS_LOC_IN_REGISTRY) that contains all the drivers
			// that are installed in the local machine.
			RegistryKey odbcDrvLocKey = OpenComplexSubKey(Registry.LocalMachine, 
				ODBC_DRIVERS_LOC_IN_REGISTRY, false);

			if (odbcDrvLocKey != null)
			{
				// Get all Driver entries defined in ODBC_DRIVERS_LOC_IN_REGISTRY.
				string [] driverNames =  odbcDrvLocKey.GetValueNames();
				odbcDrvLocKey.Close();
				if (driverNames != null)
				{
					// Foreach Driver entry in the ODBC_DRIVERS_LOC_IN_REGISTRY,
					// goto the Key ODBCINST_INI_LOC_IN_REGISTRY+driver and get
					// elements of the DSN entry to create ODBCDSN objects.
					foreach (string driverName in driverNames)
					{
						OdbcDriver odbcDriver = GetOdbcDriver(driverName);
						if (odbcDriver != null)
							driversList.Add(odbcDriver);
					}

					if (driversList.Count>0)
					{
						// Create ODBCDriver objects equal to number of valid objects
						// in the ODBC Drivers ArrayList.
						odbcDrivers = new OdbcDriver[driversList.Count];
						driversList.CopyTo(odbcDrivers,0);
					}
				}
			}
			return odbcDrivers;
		}
Exemplo n.º 2
0
		public static OdbcDriver ParseForDriver(string driverName, 
			string[] driverElements, string[] driverElmVals)
		{
			OdbcDriver odbcdriver = null;
			if (driverElements != null && driverElmVals != null)
			{
				string apilevel=null;
				string connectfunctions=null;
				string driver=null;
				string driverodbcver=null;
				string fileextns=null;
				string fileusage=null;
				string setup=null;
				string sqllevel=null;
				string usagecount=null;
				string cptimeout=null;
				string pdxuninstall=null;

				// For each element defined for a typical Driver get
				// its value.
				int i=0;
				foreach (string driverElement in driverElements)
				{
					switch (driverElement.ToLower())
					{
						case "apilevel":
							apilevel = driverElmVals[i].ToString();
							break;
						case "connectfunctions":
							connectfunctions = driverElmVals[i].ToString();
							break;
						case "driver":
							driver = driverElmVals[i].ToString();
							break;
						case "driverodbcver":
							driverodbcver = driverElmVals[i].ToString();
							break;
						case "fileextns":
							fileextns = driverElmVals[i].ToString();
							break;
						case "fileusage":
							fileusage = driverElmVals[i].ToString();
							break;
						case "setup":
							setup = driverElmVals[i].ToString();
							break;
						case "sqllevel":
							sqllevel = driverElmVals[i].ToString();
							break;
						case "usagecount":
							usagecount = driverElmVals[i].ToString();
							break;
						case "cptimeout":
							cptimeout = driverElmVals[i].ToString();
							break;
						case "pdxuninstall":
							pdxuninstall = driverElmVals[i].ToString();
							break;
					}
					i++;
				}
				odbcdriver = new OdbcDriver(
					driverName,
					apilevel,
					connectfunctions,
					driver,
					driverodbcver,
					fileextns,
					fileusage,
					setup,
					sqllevel,
					usagecount,
					cptimeout,
					pdxuninstall); 
			}

			return odbcdriver;
		}