Ejemplo n.º 1
0
 public TdsDataReader ExecuteReader(CommandBehavior behavior)
 {
     ValidateCommand("ExecuteReader");
     try {
         Execute(behavior, true);
     }
     catch (TdsTimeoutException e) {
         throw TdsException.FromTdsInternalException((TdsInternalException)e);
     }
     Connection.DataReader = new TdsDataReader(this);
     return(Connection.DataReader);
 }
Ejemplo n.º 2
0
        public void Open()
        {
            string serverName = "";

            if (connectionString == null)
            {
                throw new InvalidOperationException("Connection string has not been initialized.");
            }

            try {
                if (!pooling)
                {
                    ParseDataSource(dataSource, out port, out serverName);
                    tds = new Tds42(serverName, port, PacketSize, ConnectionTimeout);
                }
                else
                {
                    ParseDataSource(dataSource, out port, out serverName);
                    TdsConnectionInfo info = new TdsConnectionInfo(serverName, port, packetSize, ConnectionTimeout, minPoolSize, maxPoolSize);
                    pool = tdsConnectionPools.GetConnectionPool(connectionString, info);
                    tds  = pool.GetConnection();
                }
            }
            catch (TdsTimeoutException e) {
                throw TdsException.FromTdsInternalException((TdsInternalException)e);
            }

            tds.TdsErrorMessage += new TdsInternalErrorMessageEventHandler(ErrorHandler);
            tds.TdsInfoMessage  += new TdsInternalInfoMessageEventHandler(MessageHandler);

            if (!tds.IsConnected)
            {
                try {
                    tds.Connect(parms);
                    ChangeState(ConnectionState.Open);
                    ChangeDatabase(parms.Database);
                }
                catch {
                    if (pooling)
                    {
                        pool.ReleaseConnection(tds);
                    }
                    throw;
                }
            }
            else if (connectionReset)
            {
                // tds.ExecuteNonQuery ("EXEC sp_reset_connection"); FIXME
                ChangeState(ConnectionState.Open);
            }
        }
Ejemplo n.º 3
0
        public int ExecuteNonQuery()
        {
            ValidateCommand("ExecuteNonQuery");
            int result = 0;

            try {
                Execute(CommandBehavior.Default, false);
            }
            catch (TdsTimeoutException e) {
                throw TdsException.FromTdsInternalException((TdsInternalException)e);
            }

            GetOutputParameters();
            return(result);
        }
Ejemplo n.º 4
0
        public object ExecuteScalar()
        {
            ValidateCommand("ExecuteScalar");
            try {
                Execute(CommandBehavior.Default, true);
            }
            catch (TdsTimeoutException e) {
                throw TdsException.FromTdsInternalException((TdsInternalException)e);
            }

            if (!Connection.Tds.NextResult() || !Connection.Tds.NextRow())
            {
                return(null);
            }

            object result = Connection.Tds.ColumnValues [0];

            CloseDataReader(true);
            return(result);
        }