public static TDSRET try_tds_login(ref TdsLogin login, out TdsSocket tds, bool verbose = false) { tds = null; if (!login.SetPasswd(PASSWORD) || !login.SetUser(USER) || !login.SetApp("app") || !login.SetHost("myhost") || !login.SetLibrary("TDS-Library") || !login.SetServer(SERVER) || !login.SetClientCharset(CHARSET) || !login.SetLanguage("us_english")) { return(G.TDS_FAIL); } if (verbose) { Console.WriteLine("Connecting to database"); } test_context = new TdsContext(); tds = test_context.AllocSocket(512); var connection = tds.ReadConfigInfo(ref login, test_context.Locale); if (connection == null || tds.ConnectAndLogin(connection) != G.TDS_SUCCESS) { if (connection != null) { TdsContext.FreeSocket(tds); tds = null; Tds.FreeLogin(connection); } return(G.TDS_FAIL); } Tds.FreeLogin(connection); return(G.TDS_SUCCESS); }
public void TestCompiletimeSettings() { var settings = Tds.GetCompiletimeSettings(); Assert.AreEqual("auto", settings.tdsver); Assert.AreEqual("freetds v1.1.36", settings.freetds_version); }
public eXTask(List <TypedItem> list) { this.Items = list; this.Tds = DateTime.Now; CreatedAt = Tds.ToString(XFConstants.DateTimeFormat); this.Message = "Task"; if (list.ContainsKey <Guid>(XFConstants.EventWriter.MessageId)) { MessageId = list.Get <Guid>(XFConstants.EventWriter.MessageId); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } if (list.ContainsKey <string>(XFConstants.EventWriter.Message)) { Message = list.Get <string>(XFConstants.EventWriter.Message); } if (list.ContainsKey <DateTimeOffset>("metric.event.start")) { Start = list.Get <DateTimeOffset>("metric.event.start"); } if (list.ContainsKey <double>("metric.event.elapsed")) { Elapsed = list.Get <double>("metric.event.elapsed"); } if (list.ContainsKey <string>(XFConstants.TaskWriter.TaskId)) { TaskId = list.Get <string>(XFConstants.TaskWriter.TaskId); } if (list.ContainsKey <string>(XFConstants.TaskWriter.TaskMasterId)) { MasterId = list.Get <string>(XFConstants.TaskWriter.TaskMasterId); } if (list.ContainsKey <string>(XFConstants.TaskWriter.TaskType)) { TaskType = list.Get <string>(XFConstants.TaskWriter.TaskType); } if (list.ContainsKey <string>(XFConstants.TaskWriter.TaskName)) { TaskName = list.Get <string>(XFConstants.TaskWriter.TaskName); } if (list.ContainsKey <string>("event.outcome")) { TaskOutcome = list.Get <string>("event.outcome"); } Year = Tds.Year; Month = Tds.Month; Day = Tds.Day; DayOfWeek = Tds.DayOfWeek.ToString(); Hour = Tds.Hour; Minute = Tds.Minute; }
public override string ToString() { StringBuilder sb = new StringBuilder(); sb.AppendLine(String.Format("Metric: {0}", Tds.ToLocalTime())); foreach (var item in Items) { sb.AppendLine(item.ToString()); } return(sb.ToString()); }
public eXStatus(List <TypedItem> list) { this.Items = list; this.Tds = DateTime.Now; Year = Tds.Year; Month = Tds.Month; Day = Tds.Day; DayOfWeek = Tds.DayOfWeek.ToString(); Hour = Tds.Hour; Minute = Tds.Minute; CreatedAt = Tds.ToString(XFConstants.DateTimeFormat); if (list.ContainsKey <Guid>(XFConstants.EventWriter.MessageId)) { MessageId = list.Get <Guid>(XFConstants.EventWriter.MessageId); } if (list.ContainsKey <string>(XFConstants.EventWriter.Message)) { Message = list.Get <string>(XFConstants.EventWriter.Message); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } if (list.ContainsKey <string>(XFConstants.Status.Description)) { Description = list.Get <string>(XFConstants.Status.Description); } if (list.ContainsKey <string>(XFConstants.Status.ModelId)) { ModelId = list.Get <string>(XFConstants.Status.ModelId); } if (list.ContainsKey <string>(XFConstants.Status.ModelName)) { ModelName = list.Get <string>(XFConstants.Status.ModelName); } if (list.ContainsKey <string>(XFConstants.Status.ModelType)) { ModelType = list.Get <string>(XFConstants.Status.ModelType); } if (list.ContainsKey <string>(XFConstants.Status.StatusText)) { Status = list.Get <string>(XFConstants.Status.StatusText); } }
public async Task <IActionResult> CreateTds([FromBody] SaveTdsResource model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var tds = new Tds(model.SupplierId, model.Date, model.PlaceOfSupply, model.AmountPaid, model.CgstAmount, model.SgstAmount, model.IgstAmount, model.TdsAmount, model.NetAmount, AccountingUnitId, AdminId); _tdsRepository.Add(tds); await _unitOfWork.CompleteAsync(); return(Ok(_mapper.Map <Tds, TdsResource>(tds))); }
public eXError(List <TypedItem> list) { this.Items = list; this.Tds = DateTime.Now; CreatedAt = Tds.ToString(XFConstants.DateTimeFormat); if (list.ContainsKey <Guid>(XFConstants.EventWriter.MessageId)) { MessageId = list.Get <Guid>(XFConstants.EventWriter.MessageId); } if (list.ContainsKey <string>(XFConstants.EventWriter.Message)) { Message = list.Get <string>(XFConstants.EventWriter.Message); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } if (list.ContainsKey <string>(XFConstants.EventWriter.ErrorSeverity)) { Severity = list.Get <string>(XFConstants.EventWriter.ErrorSeverity).ToString(); } if (list.ContainsKey <string>(XFConstants.EventWriter.Category)) { Category = list.Get <string>(XFConstants.EventWriter.Category).ToString(); } if (list.ContainsKey <string>(XFConstants.Message.Verb)) { Verb = list.Get <string>(XFConstants.Message.Verb).ToString(); } if (list.ContainsKey <string>(XFConstants.Context.Model)) { Model = list.Get <string>(XFConstants.Context.Model).ToString(); } if (list.ContainsKey <string>(XFConstants.EventWriter.StackTrace)) { StackTrace = list.Get <string>(XFConstants.EventWriter.StackTrace); } if (list.ContainsKey <string>(XFConstants.Context.UICULTURE)) { UICulture = list.Get <string>(XFConstants.Context.UICULTURE); } if (list.ContainsKey <DateTime>(XFConstants.Context.RequestBegin)) { RequestBegin = list.Get <DateTime>(XFConstants.Context.RequestBegin); } if (list.ContainsKey <DateTime>(XFConstants.Metrics.Scope.DataRequestService.Begin)) { DataRequestBegin = list.Get <DateTime>(XFConstants.Metrics.Scope.DataRequestService.Begin); } if (list.ContainsKey <DateTimeOffset>(XFConstants.Metrics.Scope.DataRequestService.End)) { DataRequestEnd = list.Get <DateTime>(XFConstants.Metrics.Scope.DataRequestService.End); } if (list.ContainsKey <DateTimeOffset>(XFConstants.Context.RequestEnd)) { RequestEnd = list.Get <DateTime>(XFConstants.Context.RequestEnd); } if (list.ContainsKey <string>(XFConstants.Metrics.DbType)) { Dbtype = list.Get <string>(XFConstants.Metrics.DbType); if (Dbtype.Equals("sqlserver", StringComparison.OrdinalIgnoreCase)) { if (list.ContainsKey <string>(XFConstants.Metrics.Database.Datasource)) { string datastore = list.Get <string>(XFConstants.Metrics.Database.Datasource); string[] cn = datastore.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (cn != null && cn.Length == 2) { string[] server = cn[0].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (server != null && server.Length == 2) { Server = server[1]; } string[] catalog = cn[1].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); if (catalog != null && catalog.Length == 2) { Database = catalog[1]; } } } } } if (list.ContainsKey <string>(XFConstants.Metrics.Database.Command)) { var found = list.FirstOrDefault(x => x.Key.Equals(XFConstants.Metrics.Database.Command)); Command = found.Value.ToString(); CommandType = found.Scope; } if (list.ContainsKey <DateTime>(XFConstants.Metrics.Scope.Command.Begin)) { DataAccessBegin = list.Get <DateTime>(XFConstants.Metrics.Scope.Command.Begin); if (list.ContainsKey <DateTime>(XFConstants.Metrics.Scope.Command.End)) { DataAccessEnd = list.Get <DateTime>(XFConstants.Metrics.Scope.Command.End); } } if (list.ContainsKey <string>("request.uri")) { Uri = list.Get <string>("request.uri"); } if (list.ContainsKey <Guid>("app.context.instance")) { AppContextInstance = list.Get <Guid>("app.context.instance").ToString(); } if (list.ContainsKey <string>("app.context.instance")) { AppContextInstance = list.Get <string>("app.context.instance"); } if (list.ContainsKey <string>(XFConstants.Context.Ticket)) { TicketId = list.Get <string>(XFConstants.Context.Ticket); } Year = Tds.Year; Month = Tds.Month; Day = Tds.Day; DayOfWeek = Tds.DayOfWeek.ToString(); Hour = Tds.Hour; Minute = Tds.Minute; }
public void CheckNullException() { //set up dummy sql listener, if there is a real sql server on this //machine at that port, in theory this part will fail, but that's ok //becuase something will be listening on the port and that's all we //require at this point: a listener on port 1433... try{ Socket Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress hostIP = Dns.GetHostEntry("localhost").AddressList[0]; IPEndPoint ep = new IPEndPoint(hostIP, 1433); Listener.Bind(ep); Listener.Listen(1); } catch (Exception) { //ignore } //try to connect twice, in earlier failure would get null exception //on 2nd call to pool.GetConnection(); //Most of this code ripped from sqlConnection.Open() TdsConnectionPool pool; TdsConnectionPoolManager sqlConnectionPools = new TdsConnectionPoolManager(TdsVersion.tds80); TdsConnectionInfo info = new TdsConnectionInfo(SERVER /*dummyhost*/, 1433 /*port*/, 8192 /*pktsize*/, 15 /*timeout*/, 0 /*minpoolsize*/, 100 /*maxpoolsize*/, 0 /*lifetime*/); pool = sqlConnectionPools.GetConnectionPool("test", info); Tds tds = null; //this first one succeeded regardless as long as something answered //the phone on port 1433 of localhost tds = pool.GetConnection(); pool.ReleaseConnection(tds); // 2nd time thru: This will fail with nullreferenceexception // at pool.GetConnection() unless the patch by Rob Wilkens which // adds "result=null;" before retry in pool.getConnection() source //First let's pretend we're calling this test fresh, as if we //call sqlConnection.Open() again : info = new TdsConnectionInfo(SERVER /*dummyhost*/, 1433 /*port*/, 8192 /*pktsize*/, 15 /*timeout*/, 0 /*minpoolsize*/, 100 /*maxpoolsize*/, 0 /*lifetime*/); pool = sqlConnectionPools.GetConnectionPool("test", info); //Then: Test for failure (will raise uncaught exception which //causes failure of test if bug is not fixed tds = pool.GetConnection(); pool.ReleaseConnection(tds); //exit }
public eXEvent(List <TypedItem> list) { this.Items = list; this.Tds = DateTime.Now; CreatedAt = Tds.ToString(XFConstants.DateTimeFormat); if (list.ContainsKey <Guid>(XFConstants.EventWriter.MessageId)) { MessageId = list.Get <Guid>(XFConstants.EventWriter.MessageId); } if (list.ContainsKey <string>("sessionid")) { SessionId = list.Get <string>("sessionid"); } if (list.ContainsKey <string>(XFConstants.Context.PrimaryScope)) { PrimaryScope = list.Get <string>(XFConstants.Context.PrimaryScope); } if (list.ContainsKey <string>(XFConstants.Context.SecondaryScope)) { SecondaryScope = list.Get <string>(XFConstants.Context.SecondaryScope); } if (list.ContainsKey <string>(XFConstants.EventWriter.Message)) { Message = list.Get <string>(XFConstants.EventWriter.Message); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } if (list.ContainsKey <string>("xf.bigdata.usecase")) { UseCase = list.Get <string>("xf.bigdata.usecase"); } if (list.ContainsKey <DateTimeOffset>("metric.event.start")) { Start = list.Get <DateTimeOffset>("metric.event.start"); } if (list.ContainsKey <double>("metric.event.elapsed")) { Elapsed = list.Get <double>("metric.event.elapsed"); } if (list.ContainsKey <int>("usecase.resultset.count")) { ResultsetCount = list.Get <int>("usecase.resultset.count"); } if (list.ContainsKey <string>("request.uri")) { Uri = list.Get <string>("request.uri"); } if (list.ContainsKey <string>("event.outcome")) { EventOutcome = list.Get <string>("event.outcome"); } if (list.ContainsKey <Guid>("app.context.instance")) { AppContextInstance = list.Get <Guid>("app.context.instance").ToString(); } if (list.ContainsKey <string>("app.context.instance")) { AppContextInstance = list.Get <string>("app.context.instance").ToString(); } Year = Tds.Year; Month = Tds.Month; Day = Tds.Day; DayOfWeek = Tds.DayOfWeek.ToString(); Hour = Tds.Hour; Minute = Tds.Minute; }
public eXKpi(List <TypedItem> list) { this.Items = list; this.Tds = DateTime.Now; CreatedAt = Tds.ToString(XFConstants.DateTimeFormat); if (list.ContainsKey <Guid>(XFConstants.EventWriter.MessageId)) { MessageId = list.Get <Guid>(XFConstants.EventWriter.MessageId); } if (list.ContainsKey <string>("key")) { Key = list.Get <string>("key"); } if (list.ContainsKey <string>("group")) { Group = list.Get <string>("group"); } if (list.ContainsKey <string>("scopeid")) { ScopeId = list.Get <string>("scopeid"); } if (list.ContainsKey <string>("sessionid")) { SessionId = list.Get <string>("sessionid"); } if (list.ContainsKey <string>("activity")) { Activity = list.Get <string>("activity"); } if (list.ContainsKey <string>(XFConstants.EventWriter.Message)) { Message = list.Get <string>(XFConstants.EventWriter.Message); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } if (list.ContainsKey <string>("src")) { Src = list.Get <string>("src"); } if (list.ContainsKey <string>("name")) { Key = list.Get <string>("name"); } if (list.ContainsKey <string>("data")) { string s = list.Get <string>("data"); string[] t = s.Split(new char[] { ';' }); Data = new List <string>(t); } if (list.ContainsKey <int>("elapsed")) { Elapsed = list.Get <int>("elapsed"); } if (list.ContainsKey <string>(XFConstants.EventWriter.Message)) { Message = list.Get <string>(XFConstants.EventWriter.Message); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } Year = Tds.Year; Month = Tds.Month; Day = Tds.Day; DayOfWeek = Tds.DayOfWeek.ToString(); Hour = Tds.Hour; Minute = Tds.Minute; }
public eXAlert(List <TypedItem> list) { this.Items = list; this.Tds = DateTime.Now; CreatedAt = Tds.ToString(XFConstants.DateTimeFormat); string status = "none"; string disposition = String.Format("{0}:{1}", status, DateTime.Now.ToString(XFConstants.DateTimeFormat)); Dispositions = new string[] { disposition }; CurrentStatus = status; if (list.ContainsKey <Guid>(XFConstants.EventWriter.MessageId)) { MessageId = list.Get <Guid>(XFConstants.EventWriter.MessageId); } if (list.ContainsKey <string>(XFConstants.Alert.Message)) { Message = list.Get <string>(XFConstants.Alert.Message); } if (list.ContainsKey <string>(XFConstants.Context.ZONE)) { Zone = list.Get <string>(XFConstants.Context.ZONE); } if (list.ContainsKey <string>(XFConstants.Context.Application)) { ApplicationKey = list.Get <string>(XFConstants.Context.Application); } if (list.ContainsKey <string>("event.alert.title")) { Title = list.Get <string>("event.alert.title"); } if (list.ContainsKey <string>("event.alert.categories")) { string s = list.Get <string>("event.alert.categories"); if (!String.IsNullOrEmpty(s)) { string[] t = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <string> items = new List <string>(); foreach (var item in t) { items.Add(item.Trim()); } Categories = items.ToArray(); } } if (list.ContainsKey <string>("event.alert.importance")) { Importance = list.Get <string>("event.alert.importance"); } if (list.ContainsKey <string>("event.alert.urgency")) { Urgency = list.Get <string>("event.alert.urgency"); } if (list.ContainsKey <string>("event.alert.namedtarget")) { NamedRecipient = list.Get <string>("event.alert.namedtarget"); } if (list.ContainsKey <string>("event.alert.stacktrace")) { StackTrace = list.Get <string>("event.alert.stacktrace"); } if (list.ContainsKey <string>("event.alert.error")) { Error = list.Get <string>("event.alert.error"); } if (list.ContainsKey <string>("event.alert.source")) { Source = list.Get <string>("event.alert.source"); } if (list.ContainsKey <string>("event.alert.topic")) { Topic = list.Get <string>("event.alert.topic"); } if (list.ContainsKey <string>("event.alert.data")) { Data = list.Get <string>("event.alert.data"); } if (list.ContainsKey("event.alert.targets")) { string s = list.Get <string>("event.alert.targets"); if (!String.IsNullOrWhiteSpace(s)) { string[] t = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <string> items = new List <string>(); foreach (var item in t) { items.Add(item.Trim()); } Audiences = items.ToArray(); } } Year = Tds.Year; Month = Tds.Month; Day = Tds.Day; DayOfWeek = Tds.DayOfWeek.ToString(); Hour = Tds.Hour; Minute = Tds.Minute; }
public void TestServer() { Tds.DumpOpen(@"C:\T_\dump.log"); void dump_login(TdsLogin login) { Console.WriteLine("host {0}", login.ClientHostName); Console.WriteLine("user {0}", login.UserName); Console.WriteLine("pass {0}", login.Password); Console.WriteLine("app {0}", login.AppName); Console.WriteLine("srvr {0}", login.ServerName); Console.WriteLine("vers {0}.{0}", login.TdsMajor(), login.TdsMinor()); Console.WriteLine("lib {0}", login.Library); Console.WriteLine("lang {0}", login.Language); Console.WriteLine("char {0}", login.ServerCharset); Console.WriteLine("bsiz {0}", login.BlockSize); } var abc = Marshal.SizeOf <TDSPOLLWAKEUP>(); var connection = Task.Run(() => { //Common.SERVER = "localhost"; //var login = new TdsLogin(false); //var ret = Common.try_tds_login(ref login, out var tds); //if (ret != G.TDS_SUCCESS) // throw new Exception("try_tds_login() failed"); //Common.run_query(tds, "Select * From Test;"); //Common.try_tds_logout(login, tds); using (var conn = new SqlConnection("Data Source=tcp:localhost,1433;Initial Catalog=Test;MultipleActiveResultSets=False;user=guest;pwd=sybase;Encrypt=false;trustservercertificate=false")) using (var com = new SqlCommand("Select * From Table", conn)) { conn.Open(); com.ExecuteNonQuery(); } }); //NativeMethods.tdsdump_log(@"C:\T_\dump.log", 1, $"A0: {tds.Value.state}\n"); using (var ctx = new TdsContext()) { //ctx.MsgHandler = (a, b, c) => //{ // return 0; //}; ctx.ErrHandler = (a, b, c) => { return(G.TDS_INT_CONTINUE); }; //ctx.IntHandler = (a) => //{ // return 0; //}; var tds = ctx.Listen() ?? throw new Exception("Error Listening"); //tds.Conn.Env.Language = "us_english"; //tds.Conn.Env.Charset = "ISO-8859-1"; //tds.Conn.Env.Database = "master"; using (var login = tds.AllocReadLogin(0x702) ?? throw new Exception("Error reading login")) { dump_login(login); if (true || (login.UserName == "guest" && login.Password == "sybase")) { tds.OutFlag = TDS_PACKET_TYPE.TDS_REPLY; //tds.EnvChange(P.TDS_ENV_DATABASE, "master", "pubs2"); //tds.SendMsg(5701, 2, 10, "Changed database context to 'pubs2'.", "JDBC", "ZZZZZ", 1); //if (!login.Value.suppress_language) //{ // tds.EnvChange(P.TDS_ENV_LANG, null, "us_english"); // tds.SendMsg(5703, 1, 10, "Changed language setting to 'us_english'.", "JDBC", "ZZZZZ", 1); //} //tds.EnvChange(P.TDS_ENV_PACKSIZE, null, "512"); tds.SendLoginAck("Microsoft SQL Server", G.TDS_MS_VER(10, 0, 6000)); if (G.IS_TDS50(tds.Conn.Value)) { tds.SendCapabilitiesToken(); } tds.SendDoneToken(0, 1); } else { return; // send nack before exiting } tds.FlushPacket(); } var query = tds.GetGenericQuery(); Console.WriteLine("query : {0}", query); tds.OutFlag = TDS_PACKET_TYPE.TDS_REPLY; if (false) { using (var resinfo = new TdsResultInfo(1)) { resinfo.Columns[0].ColumnType = TDS_SERVER_TYPE.SYBVARCHAR; resinfo.Columns[0].ColumnSize = 30; resinfo.Columns[0].ColumnName = "name"; resinfo.CurrentRow = Marshal.StringToHGlobalAnsi("pubs2"); resinfo.Columns[0].ColumnData = resinfo.CurrentRow; //var column = resinfo.Columns[0] = new TdsColumn //{ // ColumnType = TDS_SERVER_TYPE.SYBVARCHAR, // ColumnSize = 30, // ColumnName = "name", // ColumnData = resinfo.CurrentRow, //}; tds.SendResult(resinfo); tds.SendControlToken(1); tds.SendRow(resinfo); } } tds.SendDoneToken(16, 1); tds.FlushPacket(); //Thread.Sleep((int)(.5M * 1000M)); } }
public void Setup() { Tds.Touch(); //Tds.DumpOpen(@"C:\T_\dump.log"); }