public void SetUp() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute(_dropProc); connection.Execute(_createProc); } }
public void Setup() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute(_createProc); connection.Execute(_createEchoCharProc); connection.Execute(_createEchoStringProc); connection.Execute(_createEchoBinaryProc); } }
public void Teardown() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute(_dropProc); connection.Execute(_dropEchoCharProc); connection.Execute(_dropEchoStringProc); connection.Execute(_dropEchoBinaryProc); } }
public void Teardown() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute(_dropTextLocatorProc); } }
public void ExecuteRaiseError_OutputsInfoMessages() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Open(); var infoMessages = new List <AseError>(); AseInfoMessageEventHandler handlerFunc = (sender, args) => { foreach (AseError message in args.Errors) { infoMessages.Add(message); } }; connection.InfoMessage += handlerFunc; try { connection.Execute(@"raiserror 17001 'AAA'", commandType: CommandType.Text); } catch { } connection.InfoMessage -= handlerFunc; Assert.IsNotEmpty(infoMessages); Assert.AreEqual(17001, infoMessages[0].MessageNumber); Assert.AreEqual("AAA", infoMessages[0].Message); } }
public void Teardown() { using (var connection = new AseConnection(ConnectionStrings.Default)) { connection.Execute(_dropProc); } }
public void Setup() { using (var connection = new AseConnection(ConnectionStrings.Default)) { connection.Execute(_createProc); } }
public void ExecutePrintStatements_OutputsInfoMessages() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Open(); var infoMessages = new List <AseError>(); AseInfoMessageEventHandler handlerFunc = (sender, args) => { foreach (AseError message in args.Errors) { infoMessages.Add(message); } }; connection.InfoMessage += handlerFunc; connection.Execute(@"print 'AAA' print 'BBB'", commandType: CommandType.Text); connection.InfoMessage -= handlerFunc; Assert.IsNotEmpty(infoMessages); Assert.AreEqual("AAA", infoMessages[0].Message); Assert.AreEqual("BBB", infoMessages[1].Message); } }
public void Simple_Procedure_ShouldExecute() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute("sp_test_simple", commandType: CommandType.StoredProcedure); } }
public void Setup() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { //connection.Execute(_dropTextLocatorProc); connection.Execute(_createTextLocatorProc); } }
public void Execute_InvalidBackupServerCommand_ThrowsAseException_CoreFx() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { var dbName = connection.QuerySingle <string>("select db_name()"); var ex = Assert.Throws <AseException>(() => connection.Execute($"dump database {dbName} to '/doesnotexist/foo' with compression = '101'")); Assert.Greater(ex.Errors.Count, 1); Assert.Greater(ex.Errors[0].Severity, 10); } }
public void ExecuteReader_WithMessagesEmbeddedInResultsAndFlushMessageOn_RetainsServerOrder(char withSelect, string[] expectedResults) { var results = new List <string>(); var messageEventHandler = new AseInfoMessageEventHandler((sender, eventArgs) => { foreach (AseError error in eventArgs.Errors) { results.Add(error.Message); } }); using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Open(); connection.Execute("SET FLUSHMESSAGE ON"); try { connection.InfoMessage += messageEventHandler; using (var command = connection.CreateCommand()) { command.CommandText = "[dbo].[sp_test_message_order]"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@runSelect", withSelect); command.Parameters.Add(new AseParameter("@status", AseDbType.VarChar) { Direction = ParameterDirection.Output }); using (var reader = command.ExecuteReader()) { do { while (reader.Read()) { results.Add(reader.GetString(0)); } } while (reader.NextResult()); } Assert.AreEqual("OK", command.Parameters["@status"].Value.ToString()); } } finally { connection.InfoMessage -= messageEventHandler; } } CollectionAssert.AreEqual(expectedResults, results.ToArray()); }
public void RaiserrorProcedure_ThrowsAseException() { using (var connection = new AseConnection(ConnectionStrings.Default)) { var ex = Assert.Throws <AseException>(() => connection.Execute("sp_test_raiseerror", commandType: CommandType.StoredProcedure)); var error = ex.Errors[0]; Assert.AreEqual("BAD BAD BAD", error.Message); Assert.AreEqual(ex.Message, error.Message); Assert.AreEqual(16, error.Severity); Assert.AreEqual(100000, error.MessageNumber); Assert.AreEqual(5, error.LineNum); Assert.AreEqual("sp_test_raiseerror", error.ProcName); } }
public void Teardown() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute(_dropInsertTextProc); connection.Execute(_dropEchoTextProc); connection.Execute(_dropTextTable); connection.Execute(_dropEchoTextLocatorProc); connection.Execute(_dropTrueEchoTextLocatorProc); connection.Execute(_dropTextTypeColumnProc); connection.Execute(_dropJustTextProc); } }
public void Setup() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { connection.Execute(_createEchoTextProc); connection.Execute(_createTextTable); connection.Execute(_createEchoTextLocatorProc); connection.Execute(_createTrueEchoTextLocatorProc); connection.Execute(_createTextTypeColumnProc); connection.Execute(_createJustTextProc); connection.Execute(_createInsertTextProc); } }
public void Simple_Procedure_ShouldExecute() { Logger.Enable(); using (var connection = new AseConnection(ConnectionStrings.Default)) { var p = new DynamicParameters(); p.Add("@echoChar", null, DbType.String, ParameterDirection.Output, 2); var inBinary = Guid.NewGuid().ToByteArray(); p.Add("@inBinary", inBinary); p.Add("@echoBinary", null, DbType.Binary, ParameterDirection.Output, 16); connection.Execute("sp_multitype_output", p, commandType: CommandType.StoredProcedure); Assert.AreEqual("X", p.Get <string>("@echoChar")); Assert.AreEqual(inBinary, p.Get <byte[]>("@echoBinary")); } }
public void Insert_Text_ShouldBeValid() { using (var connection = new AseConnection(ConnectionStrings.Pooled)) { using (var transaction = connection.BeginTransaction()) { using (var fragmentCommand = connection.CreateCommand()) { fragmentCommand.CommandText = "insert into test_text_table (Fragment) VALUES (@fragment)"; fragmentCommand.CommandType = CommandType.Text; fragmentCommand.Transaction = transaction; var bytesSegmentSize = 16382; //var bytesSegmentSize = 2048; var data = Enumerable.Repeat((byte)0x65, 16384).ToArray(); //var data = Enumerable.Repeat((byte) 0x65, 6380).ToArray(); var totalSegment = GetTotalSegments(data.Length, bytesSegmentSize); var pos = 0; for (var i = 1; i <= totalSegment; i++) { var len = data.Length - pos >= bytesSegmentSize ? bytesSegmentSize : (data.Length - pos); var fragment = new byte[len]; Buffer.BlockCopy(data, pos, fragment, 0, len); fragmentCommand.Parameters.Clear(); var p = fragmentCommand.CreateParameter(); p.ParameterName = @"@fragment"; p.Value = Convert.ToBase64String(fragment); p.DbType = DbType.String; p.Direction = ParameterDirection.Input; fragmentCommand.Parameters.Add(p); var status = fragmentCommand.ExecuteNonQuery(); pos += len; } var count = connection.Execute("Select Fragment from test_text_table"); transaction.Rollback(); } } } }
public static void Main(string[] args) { var ConnectionSybase = "Data Source=10.1.1.36;Port=5000;Database=cafardb;Uid=sa;Pwd=cafsyb;Charset=cp850;"; var ConnectionMaster = "Data Source=10.1.4.10;Port=5000;Database=master;Uid=sa;Pwd=cafsybweb;Charset=cp850;"; var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); logger.Info("Prueba - Iniciando Backup and Restore diario"); Console.WriteLine("Prueba - Iniciando Backup and Restore diario"); using (Process p = Process.GetCurrentProcess()) p.PriorityClass = ProcessPriorityClass.High; try { using (AseConnection _connectionSybase = new AseConnection(ConnectionSybase)) { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); try { _connectionSybase.Open(); } catch (Exception ex) { logger.Error("Error al conectarse con RDC-W2K12"); Console.WriteLine("Error al conectarse con RDC-W2K12"); logger.Error(ex.Message); Console.WriteLine(ex.Message); } if (_connectionSybase.State == System.Data.ConnectionState.Open) { var backupDiario = "cafardb" + DateTime.Now.Date.ToString("yyyyMMdd"); var pathBackupProd = "C:\\Users\\Administrator\\Desktop\\COMPARTIDO RDC-W2K12\\" + backupDiario; logger.Info("Conexión establecida"); Console.WriteLine("Conexión establecida"); if (File.Exists(pathBackupProd)) { logger.Error("Ya existe " + pathBackupProd); Console.WriteLine("Ya existe " + pathBackupProd); } else { var sqlBackup = "dump database cafardb to " + '"' + pathBackupProd + '"' + " with notify = client"; var command = _connectionSybase.CreateCommand(); command.CommandText = sqlBackup; logger.Info("Iniciando dump"); Console.WriteLine("Iniciando dump"); try { void captureResult(object sender, AseInfoMessageEventArgs aseInfoMessageEventArgs) { Console.WriteLine(aseInfoMessageEventArgs.Message); } _connectionSybase.InfoMessage += captureResult; command.ExecuteNonQuery(); logger.Info("Dump finalizado"); Console.WriteLine("Dump finalizado"); var pathBackupWeb = "\\\\10.1.2.10\\compartidosybase15\\" + backupDiario; if (File.Exists(pathBackupWeb)) { logger.Error("Ya existe " + pathBackupWeb); Console.WriteLine("Ya existe " + pathBackupWeb); } else { logger.Info("Copiando backup en SYBASE15"); Console.WriteLine("Copiando backup en SYBASE15"); File.Copy(pathBackupProd, pathBackupWeb); logger.Info("Copia de backup finalizada"); Console.WriteLine("Copia de backup finalizada"); try { using (AseConnection connectionMaster = new AseConnection(ConnectionMaster)) { logger.Info("Conectando a Sybase15"); Console.WriteLine("Conectando a Sybase15"); var sqlRestore = "load database CafarWeb from " + '"' + pathBackupWeb + '"'; connectionMaster.Open(); logger.Info("Conexion Establecida con Sybase15"); Console.WriteLine("Conexion Establecida con Sybase15"); var procesos = connectionMaster.Query <Procces>("sp_who sa").ToList(); var procesoSaCafarNov = procesos.Where(x => x.dbname == "CafarNov" || x.dbname == "CafarWeb"); if (procesoSaCafarNov.Any()) { logger.Info("Limpiando procesos sa en SYBASE15"); Console.WriteLine("Limpiando procesos sa en SYBASE15"); } foreach (Procces proceso in procesoSaCafarNov) { try { connectionMaster.Execute("kill " + proceso.spid); } catch (Exception ex) { Console.WriteLine(ex.Message); logger.Error(ex.Message); } } //_connectionWeb.Open(); logger.Info("Iniciando Restore"); Console.WriteLine("Iniciando Restore"); connectionMaster.Execute(sqlRestore); logger.Info("Restore Finalizado en Web"); Console.WriteLine("Restore Finalizado en Web"); connectionMaster.Execute("Online database CafarWeb"); logger.Info("Bases de Datos puesta OnLine"); Console.WriteLine("Bases de Datos puesta OnLine"); connectionMaster.Close(); connectionMaster.Dispose(); } } catch (Exception ex) { logger.Error(ex.Message); Console.WriteLine(ex.Message); } } } catch (Exception ex) { logger.Error(ex.Message); Console.WriteLine(ex.Message); } } _connectionSybase.Close(); } } } catch (Exception ex) { logger.Error(ex.Message); logger.Error("Error"); Console.WriteLine(ex.Message); } }