context: using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Data;
  using System.Data.Common;
  using System.Data.SqlClient;
  using System.Data.OleDb;
  using System.Data.Odbc;
  
  namespace RainstormStudios.Data
  {
      /// <summary>
      /// Provides static methods for working with database connection strings and data type conversions.  This class is sealed.
      /// </summary>
      public sealed class rsData
      {
          #region Public Methods
          //***************************************************************************
          // Static Methods
          // 
          /// <summary>
          /// Attempts to determine the proper value of the RainstormStudios.AdoProviderType enumeration based on the given connection string.
          /// </summary>
          /// <param name="ConnString">The connnectino string to parse.</param>
          /// <returns>A value from the RainstormStudios.AdoProviderType enumeration.</returns>
          public static AdoProviderType ParseProviderType(string ConnString)
          {
              return RainstormStudios.rsString.ParseProviderType(ConnString);
          }
          /// <summary>
          /// Converts a system data type to the OdbcType enum member that most closely matches.
          /// </summary>
          /// <param name="value">A Type object indicating the data type to convert.</param>
          /// <returns></returns>
          public static SqlDbType GetSqlDataType(Type value)
          {
              return rsData.GetSqlDataType(value.Name);
          }
          /// <summary>
          /// Converts a system data type to the OdbcType enum member that most closely matches.
          /// </summary>
          /// <param name="value">A string value containing the name of the system data type to convert.</param>
          /// <returns></returns>
          public static SqlDbType GetSqlDataType(string value)
          {
              SqlDbType retVal = SqlDbType.VarChar;
              string tName = (value.IndexOf('.') > -1) ? value.Substring(value.LastIndexOf('.') + 1) : value;
              switch (tName)
              {
                  case "String":
                      retVal = SqlDbType.VarChar;
                      break;
                  case "Boolean":
                      retVal = SqlDbType.Bit;
                      break;
                  case "Byte":
                      retVal = SqlDbType.TinyInt;
                      break;
                  case "Int16":
                      retVal = SqlDbType.SmallInt;
                      break;
                  case "Int32":
                      retVal = SqlDbType.Int;
                      break;
                  case "Int64":
                      retVal = SqlDbType.BigInt;
                      break;
                  case "Single":
                      retVal = SqlDbType.Real;
                      break;
                  case "Double":
                      retVal = SqlDbType.Float;
                      break;
                  case "DateTime":
                      retVal = SqlDbType.DateTime;
                      break;
                  case "Decimal":
                      retVal = SqlDbType.Decimal;
                      break;
                  case "Char":
                      retVal = SqlDbType.VarChar;
                      break;
                  case "Image":
                      retVal = SqlDbType.Image;
                      break;
                  case "Byte[]":
                      retVal = SqlDbType.Binary;
                      break;
                  case "Guid":
                      retVal = SqlDbType.UniqueIdentifier;
                      break;
                  default:
                      retVal = SqlDbType.Variant;
                      break;
              }
              return retVal;
          }
          /// <summary>
          /// Converts a system data type to the OdbcType enum member that most closely matches.
          /// </summary>
          /// <param name="value">A Type object indicating the data type to convert.</param>
          /// <returns></returns>
          public static OleDbType GetOleDataType(Type value)
          {
              return rsData.GetOleDataType(value.Name);
          }
          /// <summary>
          /// Converts a system data type to the OdbcType enum member that most closely matches.
          /// </summary>
          /// <param name="value">A String value containing the name of the system data type to convert.</param>
          /// <returns></returns>
          public static OleDbType GetOleDataType(string value)
          {
              OleDbType retVal = OleDbType.IUnknown;
              string tName = (value.IndexOf('.') > -1) ? value.Substring(value.LastIndexOf('.') + 1) : value;
              switch (tName)
              {
                  case "String":
                      retVal = OleDbType.VarChar;
                      break;
                  case "Boolean":
                      retVal = OleDbType.Boolean;
                      break;
                  case "Byte":
                      retVal = OleDbType.TinyInt;
                      break;
                  case "Int16":
                      retVal = OleDbType.SmallInt;
                      break;
                  case "Int32":
                      retVal = OleDbType.Integer;
                      break;
                  case "Int64":
                      retVal = OleDbType.BigInt;
                      break;
                  case "Single":
                      retVal = OleDbType.Single;
                      break;
                  case "Double":
                      retVal = OleDbType.Double;
                      break;
                  case "DateTime":
                      retVal = OleDbType.Date;
                      break;
                  case "Decimal":
                      retVal = OleDbType.Decimal;
                      break;
                  case "Char":
                      retVal = OleDbType.VarChar;
                      break;
                  case "Image":
                      retVal = OleDbType.Binary;
                      break;
                  case "Byte[]":
                      retVal = OleDbType.Binary;
                      break;
                  case "Guid":
                      retVal = OleDbType.Guid;
                      break;
                  default:
                      retVal = OleDbType.Variant;
                      break;
              }
              return retVal;
          }
          /// <summary>
          /// Converts a system data type to the OdbcType enum member that most closely matches.
          /// </summary>
          /// <param name="value">A Type object indicating the data type to convert.</param>
          /// <returns></returns>
          public static OdbcType GetOdbcDataType(Type value)
          {
              return rsData.GetOdbcDataType(value.Name);
          }
          /// <summary>
          /// Converts a system data type to the OdbcType enum member that most closely matches.
          /// </summary>
          /// <param name="value">A String value containing the name of the system data type to convert.</param>
          /// <returns></returns>
          public static OdbcType GetOdbcDataType(string value)
          {
              OdbcType retVal = OdbcType.VarChar;
              string tName = (value.IndexOf('.') > -1) ? value.Substring(value.LastIndexOf('.') + 1) : value;
              switch (tName)
              {
                  case "String":
                      retVal = OdbcType.VarChar;
                      break;
                  case "Boolean":
                      retVal = OdbcType.Bit;
                      break;
                  case "Byte":
                      retVal = OdbcType.TinyInt;
                      break;
                  case "Int16":
                      retVal = OdbcType.SmallInt;
                      break;
                  case "Int32":
                      retVal = OdbcType.Int;
                      break;
                  case "Int64":
                      retVal = OdbcType.BigInt;
                      break;
                  case "Single":
                      retVal = OdbcType.Real;
                      break;
                  case "Double":
                      retVal = OdbcType.Double;
                      break;
                  case "DateTime":
                      retVal = OdbcType.DateTime;
                      break;
                  case "Decimal":
                      retVal = OdbcType.Decimal;
                      break;
                  case "Char":
                      retVal = OdbcType.VarChar;
                      break;
                  case "Image":
                      retVal = OdbcType.Image;
                      break;
                  case "Byte[]":
                      retVal = OdbcType.Binary;
                      break;
                  case "Guid":
                      retVal = OdbcType.UniqueIdentifier;
                      break;
                  default:
                      retVal = OdbcType.VarChar;
                      break;
              }
              return retVal;
          }
          /// <summary>
          /// Parses a given QueryString to determine the base table name specified in the query.
          /// </summary>
          /// <param name="QueryString">The query to parse.</param>
          /// <returns>A string value containing the base table name from the query with all leading/trailing spaces removed.</returns>
          public static string[] ParseBaseTableName(string QueryString)
          {
              return rsString.ParseBaseTableName(QueryString, false);
          }
          /// <summary>
          /// Parses a given QueryString to determine the base table name specified in the query.
          /// </summary>
          /// <param name="QueryString">The query to parse.</param>
          /// <param name="RemoveQualifier">If set to true, all table qualifiers are removed from the returned value.</param>
          /// <returns>A string value containing the base table name from the query with all leading/trailing spaces removed.</returns>
          public static string[] ParseBaseTableName(string QueryString, bool RemoveQualifier)
          {
              return rsString.ParseBaseTableName(QueryString, RemoveQualifier);
          }
          /// <summary>
          /// Checks the given connection string for validity by attempting to open a connection with it.
          /// </summary>
          /// <param name="ConnectionString">The connection string to test.</param>
          /// <param name="ProviderArg">An integer (as enumerated in AosCommon.ProviderType) indicating the ADO.NET adapter to use.</param>
          /// <returns>A true or false value indicating whether or not the test was successful.</returns>
          public static bool CheckConnectionString(string ConnectionString, AdoProviderType ProviderArg)
          {
              #region Status Output
  #if DEBUG
              Console.WriteLine("Checking connection string validity...");
  #endif
              #endregion
              try
              {
                  string ServerVersion = "", ConnState = "";
                  switch (ProviderArg)
                  {
                      case AdoProviderType.Auto:
                          return rsData.CheckConnectionString(ConnectionString, rsData.ParseProviderType(ConnectionString));
                      case AdoProviderType.SqlProvider:
                          using (SqlConnection conTest = new SqlConnection(ConnectionString))
                          {
                              conTest.Open();
                              ServerVersion = conTest.ServerVersion;
                              ConnState = conTest.State.ToString();
                              conTest.Close();
                          }
                          break;
                      case AdoProviderType.OleProvider:
                          #region Status Output
  #if DEBUG
                          Console.WriteLine("OleDb provider found.  Creating connection...");
  #endif
                          #endregion
                          using (OleDbConnection conOle = new OleDbConnection(ConnectionString))
                          {
                              conOle.Open();
                              ServerVersion = conOle.ServerVersion;
                              ConnState = conOle.State.ToString();
                              conOle.Close();
                          }
                          break;
                      case AdoProviderType.DB2Provider:
                          //using (DB2Connection conDb2 = new DB2Connection(ConnectionString))
                          //{
                          //    conDb2.Open();
                          //    ServerVersion = conDb2.ServerVersion;
                          //    ConnState = conDb2.State.ToString();
                          //    conDb2.Close();
                          //}
                          //break;
                          throw new ArgumentException("DB2 Connection Types are not supported by this function.");
                      case AdoProviderType.OdbcProvider:
                          using (OdbcConnection conOdbc = new OdbcConnection(ConnectionString))
                          {
                              conOdbc.Open();
                              ServerVersion = conOdbc.ServerVersion;
                              ConnState = conOdbc.State.ToString();
                              conOdbc.Close();
                          }
                          break;
                      default:
                          // We got something unhandled, so inform the user & break.
                          // This *should* only ever occur if there is a an error in the calling program.
                          throw new Exception("Invalid provider type.");
                  }
                  #region Status Output
  #if DEBUG
                  Console.WriteLine("Connection string valid.  Returning true...");
  #endif
                  #endregion
                  return true;
              }
              catch (System.Data.SqlClient.SqlException)
              { return false; }
              catch (System.Data.OleDb.OleDbException)
              { return false; }
              catch (System.Data.Odbc.OdbcException)
  
gt:             { return false; }