Пример #1
0
    /// <summary>
    /// 通过连接 SQL Server Express LocalDB 实例,创建 SQL Server 数据库访问器
    /// </summary>
    /// <param name="database">数据库名称或者数据库文件路径</param>
    /// <param name="configuration">SQL Server 配置</param>
    /// <returns>SQL Server 数据库访问器</returns>
    public static SqlDbExecutor ConnectLocalDB( string database, SqlDbConfiguration configuration = null )
    {

      configuration = configuration ?? SqlServerExpress.Configuration;
      return Connect( database, @"(LocalDB)\" + configuration.LocalDBInstanceName, configuration );

    }
Пример #2
0
    /// <summary>
    /// 从配置文件中读取连接字符串并创建 SQL Server 数据库访问器
    /// </summary>
    /// <param name="name">连接字符串配置名称</param>
    /// <param name="configuration">SQL Server 数据库配置</param>
    /// <returns>SQL Server 数据库访问器</returns>
    public static SqlDbExecutor FromConfiguration( string name, SqlDbConfiguration configuration = null )
    {
      var setting = ConfigurationManager.ConnectionStrings[name];
      if ( setting == null )
        throw new InvalidOperationException();

      return Connect( setting.ConnectionString, configuration );
    }
Пример #3
0
    /// <summary>
    /// 通过指定的用户名和密码登陆 SQL Server 数据库,以创建 SQL Server 数据库访问器
    /// </summary>
    /// <param name="dataSource">数据库服务器实例名称</param>
    /// <param name="initialCatalog">数据库名称</param>
    /// <param name="userID">登录数据库的用户名</param>
    /// <param name="password">登录数据库的密码</param>
    /// <param name="pooling">是否启用连接池(默认启用)</param>
    /// <param name="configuration">SQL Server 数据库配置</param>
    /// <returns>SQL Server 数据库访问器</returns>
    public static SqlDbExecutor Connect( string dataSource, string initialCatalog, string userID, string password, bool pooling = true, SqlDbConfiguration configuration = null )
    {
      var builder = new SqlConnectionStringBuilder()
      {
        DataSource = dataSource,
        InitialCatalog = initialCatalog,
        IntegratedSecurity = false,
        UserID = userID,
        Password = password,
        Pooling = pooling
      };

      return Connect( builder.ConnectionString, configuration );
    }
Пример #4
0
        /// <summary>
        /// 创建 SqlServer 数据库查询执行程序
        /// </summary>
        /// <param name="connectionString">连接字符串</param>
        /// <param name="configuration">当前要使用的数据库配置信息</param>
        public SqlDbExecutor(string connectionString, SqlDbConfiguration configuration)
            : base(configuration)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }



            ConnectionString = connectionString;
            Configuration    = configuration;
        }
Пример #5
0
    /// <summary>
    /// 通过连接 SQL Server Express 指定实例,创建 SQL Server 数据库访问器
    /// </summary>
    /// <param name="database">数据库名称或者数据库文件路径</param>
    /// <param name="datasource">SQL Server 实例名称</param>
    /// <param name="configuration">SQL Server 配置</param>
    /// <returns>SQL Server 数据库访问器</returns>
    private static SqlDbExecutor Connect( string database, string datasource, SqlDbConfiguration configuration = null )
    {
      var builder = new SqlConnectionStringBuilder()
      {
        DataSource = datasource,
        IntegratedSecurity = true,
      };


      if ( database.IndexOfAny( Path.GetInvalidPathChars() ) == -1 && Path.IsPathRooted( database ) )
        builder.AttachDBFilename = database;

      else
        builder.InitialCatalog = database;


      return SqlServer.Connect( builder.ConnectionString, configuration );
    }
 public SqlDbExecutorWithTransaction(SqlDbTransactionContext transaction, SqlDbConfiguration configuration)
     : base(transaction.Connection.ConnectionString, configuration)
 {
     TransactionContext = transaction;
 }
 internal SqlDbTransactionContext(string connectionString, SqlDbConfiguration configuration)
 {
     Connection = new SqlConnection(connectionString);
     _executor  = new SqlDbExecutorWithTransaction(this, configuration);
 }
Пример #8
0
 /// <summary>
 /// 从现有的 SQL Server 数据库配置中创建一个数据库配置
 /// </summary>
 /// <param name="configuration">现有的数据库配置</param>
 public SqlDbConfiguration(SqlDbConfiguration configuration) : base(configuration)
 {
 }
Пример #9
0
 /// <summary>
 /// 通过指定的连接字符串构建器创建 SQL Server 数据库访问器
 /// </summary>
 /// <param name="builder">连接字符串构建器</param>
 /// <param name="configuration">SQL Server 数据库配置</param>
 /// <returns>SQL Server 数据库访问器</returns>
 public static SqlDbExecutor Connect( SqlConnectionStringBuilder builder, SqlDbConfiguration configuration = null )
 {
   return Connect( builder.ConnectionString, configuration );
 }
Пример #10
0
 /// <summary>
 /// 通过指定的连接字符串并创建 SQL Server 数据库访问器
 /// </summary>
 /// <param name="connectionString">连接字符串</param>
 /// <param name="configuration">SQL Server 数据库配置</param>
 /// <returns>SQL Server 数据库访问器</returns>
 public static SqlDbExecutor Connect( string connectionString, SqlDbConfiguration configuration = null )
 {
   return new SqlDbExecutor( connectionString, configuration ?? Configuration );
 }
Пример #11
0
 /// <summary>
 /// 从现有的 SQL Server 数据库配置中创建一个数据库配置
 /// </summary>
 /// <param name="configuration">现有的数据库配置</param>
 public SqlDbConfiguration( SqlDbConfiguration configuration ) : base( configuration ) { }