I am trying to have a stable connection to a MySQL database hosted on Amazon Web Services. Periodically when starting the application, I will get the exception:
Handshake failed due to an unexpected packet format
This is a WinForm C# application using MySQL.Data.dll V6.9.9
Here is my code for connecting:
using (var conn = new MySqlConnection(m_connectionString))
{
try
{
conn.Open();
Console.WriteLine("Connected to database");
}
catch (MySqlException ex)
{
validConnectionFound = false;
Console.WriteLine(ex);
MessageBox.Show("Unable to connect to Database. Check your network connection and try again", "Database connection Not Found");
}
catch (CryptographicException ex)
{
validConnectionFound = false;
MessageBox.Show("Cryptographic Exception: " + ex.Message);
Environment.Exit(0);
}
catch(IOException ex)
{
validConnectionFound = false;
DebugTrace.TraceWrite(m_defaultTraceSource, TraceEventType.Error, "Incorrect certificate. Please update security certificate. Exception: " + ex.Message);
MessageBox.Show("IO Exception: " + ex.Message);
Environment.Exit(0);
}
}
My connection string is in the following format:
"user id=user;password=1234;server=amazonserver.com;database=myDatabase;convertzerodatetime=True;port=3306;sslmode=VerifyCA"
I have tried both wireless and wired connections, changing the SSL mode required (VerifyCA, Required, VerifyFull, None), and adding Amazons CA to my computers trusted root certificates.
Any insight on why I am getting this exception is appreciated.
Turns out the issue was not code related. After sniffing packets with Wireshark, I found the problem was with a faulty network switch losing packets.
Related
I have a service-bus receiver instance running as a continuous running webjob, and there is requirement to Refresh the primary connection string 6 months once
what I learnt was if i am refreshing the connection string using azure portal then the existing receiver instance should throw unauthorized exception, but to my surprise its not throwing any exception it runs for 20 min or so and stops receiving message without any exception.
My Question here is that without getting the exception I cannot hit the key vault and create new instance of the receiver, is there any other alternative way for doing this ?
I have create a prototype of my application and the service bus package I am using is
WindowsAzure.ServiceBus 4.1.8 and running it using a console application.
static void Main(string[] args)
{
try
{
var factory = MessagingFactory.CreateFromConnectionString("connectionstring");
factory.PrefetchCount = 1;
var queue = factory.CreateMessageReceiver("test");
var options = new OnMessageOptions()
{
MaxConcurrentCalls = 1,
AutoComplete = false
};
Console.WriteLine(DateTime.Now);
queue.OnMessageAsync(HandleMessageReceived, options);
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("exception caught" + ex.Message);
throw;
}
}
and this is my message handler
async static Task HandleMessageReceived(BrokeredMessage brokeredMessage)
{
try
{
await brokeredMessage.CompleteAsync();
Console.WriteLine("Message Processing completed");
}
catch (Exception ex)
{
Console.WriteLine("Message Handlet exception" + ex.Message);
Console.WriteLine("has hit the catch of message handler ");
throw;
}
}
After Starting the application and it completes few messages from test queue i go to portal and regenerate my primary keys.
I have a console app using the Graph API to process pdfs sent to an email address. I am trying to set up my api to serve the pdfs, which is in another project. I have my authentication and client creation for graph in a dll, so that is all done the same, and uses the same Azure AD application info. In the console app, everything works great, but in the API it is not working.Do I have to provision the API as a separate app in Azure? That's all I can think of. Te code is literally the same right now, and not working. No errors or anything, just hangs forever trying to get anything from Office 365.
Thanks.
The below is the working code:
try
{
client = AuthenticationHelper.GetAuthenticatedClientForApp();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Acquiring a token failed with the following
error: {0}", ex.Message);
if (ex.InnerException != null)
{
//You should implement retry and back-off logic per the
guidance given here:http://msdn.microsoft.com/en-us/library/dn168916.aspx
//InnerException Message will contain the HTTP error status
codes mentioned in the link above
Console.WriteLine("Error detail: {0}",
ex.InnerException.Message);
}
Console.ResetColor();
Console.ReadKey();
return;
}
try
{
String email = "mail#example.com";
Console.WriteLine("\nRetreiving email from: " + email);
var folders = client.Users[email].MailFolders.Inbox.ChildFolders.Request().GetAsync().Result;
This is the code that fails:
try
{
client = AuthenticationHelper.GetAuthenticatedClientForApp();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Acquiring a token failed with the following error: {0}", ex.Message);
if (ex.InnerException != null)
{
//You should implement retry and back-off logic per the guidance given here:http://msdn.microsoft.com/en-us/library/dn168916.aspx
//InnerException Message will contain the HTTP error status codes mentioned in the link above
Console.WriteLine("Error detail: {0}", ex.InnerException.Message);
}
Console.ResetColor();
Console.ReadKey();
return null;
}
Attachment attachment = null;
try
{
String email = "email#example.com";
var folders = client.Users[email].MailFolders.Inbox.ChildFolders.Request().GetAsync().Result;
Please find the below code:
MQEnvironment.Hostname = HostName;
MQEnvironment.Channel = Channel;
if (!string.IsNullOrEmpty(SSLKeyRepository))
{
MQEnvironment.SSLCipherSpec = SSLCipherSpec;
MQEnvironment.SSLKeyRepository = SSLKeyRepository;
}
if (Port > 0)
MQEnvironment.Port = Port;
try
{
MQManager = new MQQueueManager(QueueManager);
try
{
MQRequestQueue = MQManager.AccessQueue(QueueNameGet, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
MQResponseQueue = MQManager.AccessQueue(QueueNameGet, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
return true;
}
catch (IBM.WMQ.MQException exIBM)
{
CloseConnection();
ErrorCode = exIBM.Reason;
ErrorDescription = exIBM.Message;
}
}
catch (IBM.WMQ.MQException exIBM)
{
CloseConnection();
ErrorCode = exIBM.Reason;
ErrorDescription = exIBM.Message;
}
catch (Exception ex)
{
CloseConnection();
ErrorCode = Constants.SYSTEMEXCEPTION;
ErrorDescription = ex.Message;
}
return false;
Issue: I am not getting the issue when I run it for single or 2-3 times. But I get the issue when it runs in a loop for multiple times.
Also, I have tried to run the same piece of code for 10,000 times from the IIS server and it ran successfully.
I am getting the issue only when I have this code on IIS webservice and that webservice is getting called multiple times.
IBM MQ client 7.5.0.0 installed on the IIS server and I am using the dll of the same version.
UPDATE
Error description:
Error Message The handle is invalid
StackTrace at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly) at System.Diagnostics.Process.get_Modules() at IBM.WMQ.CommonServices.TraceEnvironment() at IBM.WMQ.CommonServices.CreateCommonServices() at IBM.WMQ.CommonServices.TraceEnabled() at IBM.WMQ.MQBase..ctor() at IBM.WMQ.MQManagedObject..ctor()
Thanks for providing the call stack. The issue you mention is very similar to the one fixed here in MQ version 7.5.0.2. As you are at MQ v7.5.0.0, I suggest you to upgrade your MQ client to the latest level, MQ v7.5.0.7 and try.
I have said this many times here and it applies to both Java and .NET, the MQEnvironment class is NOT thread safe. By using it, you are shooting yourself in the foot.
Put the values (channel, hostname & port #) into a HashTable and pass the HashTable to the MQQueueManager class.
Hashtable qMgrHT = new Hashtable();
qMgrHT.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
qMgrHT.Add(MQC.HOST_NAME_PROPERTY, "10.10.10.10");
qMgrHT.Add(MQC.CHANNEL_PROPERTY, "TEST.CHL");
qMgrHT.Add(MQC.PORT_PROPERTY, 1414);
qMgrHT.Add(MQC.USER_ID_PROPERTY, "myUserID");
qMgrHT.Add(MQC.PASSWORD_PROPERTY, "myPwd");
MQQueueManager qMgr = new MQQueueManager(qManager, qMgrHT);
Finally, write your code so that it maintains a connection rather than connecting and disconnecting over and over. Very, VERY bad form.
the problem: While not using a VPN, the code below works fine. As soon as I connect to my home network via a VPN the, code throws an exception (translated from german):
A connection attempt failed because the connected party did not properly respond after a certain period of time, or established connection failed because connected host has failed to respond. (Exception from HRESULT: 0x8007274C).
The target "192.168.180.58" is an another computer within my home network.
Windows Store test code:
private async void createConnection(object sender, RoutedEventArgs e)
{
HostName target = new HostName("192.168.180.58");
string port = "8181";
using (StreamSocket client = new StreamSocket())
{
try
{
await client.ConnectAsync(target, port);
}
catch (Exception ex)
{
string typeName = ex.GetType().Name;
string msg = ex.Message;
}
}
}
I created a Windows Console Program (.NET 4.5.1) that is working in both situations (connected by using vpn and not using a vpn).
Windows Console test code:
namespace caPing
{
class Program
{
static void Main(string[] args)
{
string target = "192.168.180.58";
int port = 8181;
TcpClient client = new TcpClient();
try
{
client.Connect(target, port);
client.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
}
}
It looks like that the problem is somehow related to the execution environment for Windows Store Apps (when using a vpn).
What is the problem here and how can I solve it?
Kind regards,
Sörnt
I was facing the same problem then i found that
We can not keep two app running at the same time.
If Server app is running and then run the client app, the server app will
suspend and the client app will fail with connect.
You can create a server application as a desktop app, so that the client and
server can run at the same time.
From MSDN Here.
A button on the aspx page checks whether the connection with the DB2 database server is established or not. My connection String is :
Server=xx.xx.xx.xx:446; Database=dd_unit; UID=db2admin; PWD=Secure*888; CurrentSchema=ptdd;
It is throwing me a SQL30081N error message:
$exception {"ERROR [08001] [IBM] SQL30081N A communication error has been detected. Communication protocol being used: \"TCP/IP\".
Communication API being used: \"SOCKETS\". Location where the error
was detected: \"xx.xx.xx.xx\". Communication function detecting the
error: \"connect\". Protocol specific error code(s): \"10060\",
\"\", \"\". SQLSTATE=08001\r\n"} System.Exception
{IBM.Data.DB2.DB2Exception}
I looked for the SQL30081N error and it is due to connection was terminated by the network by the tcp-ip layer. Now, does the problem is with the Connection String or is it something else? Kindly help me solve this issue.
Code: (Its throwing error after connection is opened)
protected void Button3_Click(object sender, EventArgs e)
{
DB2Connection con = new DB2Connection("Server=xx.xx.xx.xx:446; Database=MyDb; UID=MyUser; PWD=MyPass; CurrentSchema=ptdd;");
try
{
con.Open();
Label1.Visible = true;
Label1.Text = "Conection done";
con.Close();
}
catch (Exception)
{
Label1.Text = "connection failed";
}
P.S. I'm using this to test my application
Port specified was incorrect. It must be 50000 as it is a tcp/ip connection