示例#1
0
        public SqlStatement(CommandType commandType, string commandText, string connectionStringName)
        {
            string      key     = ("DataConnection_" + connectionStringName);
            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                _connection = ((DbConnection)(context.Items[(key + "_connection")]));
            }
            if (_connection == null)
            {
                _canCloseConnection = true;
                _connection         = CreateConnection(connectionStringName, false, out _parameterMarker, out _leftQuote, out _rightQuote);
            }
            _command             = SqlStatement.CreateCommand(_connection);
            _command.CommandType = commandType;
            _command.CommandText = ParseSql(commandText);
            if (!(_canCloseConnection))
            {
                _command.Transaction = ((DbTransaction)(HttpContext.Current.Items[(key + "_transaction")]));
                _parameterMarker     = ((string)(HttpContext.Current.Items[(key + "_parameterMarker")]));
                _leftQuote           = ((string)(HttpContext.Current.Items[(key + "_leftQuote")]));
                _rightQuote          = ((string)(HttpContext.Current.Items[(key + "_rightQuote")]));
            }
        }
示例#2
0
        public SqlStatement(CommandType commandType, string commandText, string connectionStringName)
        {
            ConnectionStringSettings settings = ConnectionStringSettingsFactory.Create(connectionStringName);
            DbProviderFactory        factory  = DbProviderFactories.GetFactory(settings.ProviderName);

            _connection = factory.CreateConnection();
            _connection.ConnectionString = settings.ConnectionString;
            _command             = SqlStatement.CreateCommand(_connection);
            _command.CommandType = commandType;
            _command.CommandText = ParseSql(commandText);
            _parameterMarker     = ConvertTypeToParameterMarker(settings.ProviderName);
        }