Ejemplo n.º 1
0
 Task ProcessClientAsync(TdsContext tdsContext, CancellationTokenSource cancelTokenSource)
 {
     try
     {
         var client = tdsContext.Client;
         while (!client.IsDead)
         {
             var command = client.GetGenericQuery();
             tdsContext.Request = TdsRequest.Parse(command);
             using (tdsContext.Response = new TdsResponse(client))
                 _handler(tdsContext);
             client.FlushPacket();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception: {e.Message}");
         if (e.InnerException != null)
         {
             Console.WriteLine($"Inner exception: {e.InnerException.Message}");
         }
         Console.WriteLine("Connection closed.");
     }
     return(Task.CompletedTask);
 }
Ejemplo n.º 2
0
        Task <TdsContext> ProcessLoginAsync(TdsSocket client, CancellationTokenSource cancelTokenSource)
        {
            TdsContext tdsContext = null;

            try
            {
                var login = client.AllocReadLogin(0x702) ?? throw new Exception("Error reading login");
                if (login.UserName != "guest" && login.Password != "sybase")
                {
                    return(Task.FromResult(tdsContext));
                }
                client.OutFlag = TDS_PACKET_TYPE.TDS_REPLY;
                //client.EnvChange(P.TDS_ENV_DATABASE, "master", "pubs2");
                //client.SendMsg(5701, 2, 10, "Changed database context to 'pubs2'.", "JDBC", "ZZZZZ", 1);
                if (!login.Value.suppress_language)
                {
                    //client.EnvChange(P.TDS_ENV_LANG, null, "us_english");
                    //client.SendMsg(5703, 1, 10, "Changed language setting to 'us_english'.", "JDBC", "ZZZZZ", 1);
                }
                //client.EnvChange(P.TDS_ENV_PACKSIZE, null, "512");
                client.SendLoginAck("Microsoft SQL Server", G.TDS_MS_VER(10, 0, 6000));
                if (G.IS_TDS50(client.Conn.Value))
                {
                    client.SendCapabilitiesToken();
                }
                client.SendDoneToken(0, 1);
                client.FlushPacket();
                return(Task.FromResult(new TdsContext(client, cancelTokenSource.Token)));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception: {e.Message}");
                if (e.InnerException != null)
                {
                    Console.WriteLine($"Inner exception: {e.InnerException.Message}");
                }
                return(Task.FromResult(tdsContext));
            }
        }