示例#1
0
 private void PrepareConnection(DbCommandWrapper info)
 {
     if (info.Trace)
     {
         Logger.Info("begin prepare connection: " + info);
     }
     if (null == info.Connection)
     {
         if (string.IsNullOrWhiteSpace(info.ConnectionString))
         {
             info.ConnectionString = "default";
         }
         if (null == ConnectionProvider)
         {
             if (info.ConnectionString == "default")
             {
                 info.ConnectionString = "Server=(local);Trusted_Connection=true";
             }
             if (info.ConnectionString.Contains(";"))
             {
                 info.Connection = new SqlConnection(info.ConnectionString);
             }
             else
             {
                 throw new Exception("no connection provider setup");
             }
         }
         else
         {
             info.Connection = ConnectionProvider.GetConnection(info.ConnectionString);
         }
         if (null == info.Connection)
         {
             throw new Exception("cannot retrieve connection for " + info.ConnectionString);
         }
     }
     if (info.Dialect == DbDialect.None)
     {
         if (info.Connection is SqlConnection)
         {
             info.Dialect = DbDialect.SqlServer;
         }
         else if (info.Connection.GetType().Name.ToLowerInvariant().Contains("pg"))
         {
             info.Dialect = DbDialect.PostGres;
         }
         else
         {
             info.Dialect = DbDialect.Ansi;
         }
     }
     if (info.Trace)
     {
         Logger.Info("end prepare connection: " + info);
     }
 }