I am using .Net application with web service(.net) and oracle database. But when i send some request to the server and waiting for the result it is giving following error
The underlying connection was closed: An unexpected error occurred
I am unable to get the cause of the error. Can any one plese help me to get actual cause of this error and what i need to do solution. This errror occurce only in Production Server. Same code in Dev and Test server it is working.
This is probably caused by the error inside web service method or function that you are calling. Just create proper error handling and log web service exception. Here is my sample code:
[WebMethod]
public void MyServerMethod()
{
try
{
//open connection and execute your calls to Oracle DB...
}
catch (Exception ex)
{
LogServiceException(ex);
throw ex;
}
}
void LogServiceException(Exception ex)
{
string fullMessage = ex.Message;
while (ex.InnerException != null)
{
ex = ex.InnerException;
fullMessage += " Inner exception: " + ex.Message;
}
//log your exception to log file, DB or eventlog...
//in this case I will use log file, just make sure you appropriate filesystem rights to do this...
System.IO.File.AppendAllText("LogFile.txt", fullMessage);
}
Related
even though the connection string is ok as far as i know, it seems like it cannot gather the information that requires.
The account is local and all of the tables/databases have been created. I simply dont know where the error is.
ive tried changing the connection string like 5 times and nothing has improoved
the exception presented : MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Expected end of data packet
private async Task LoopingActions()
{
string command = "SELECT * FROM `data`.`messages` LIMIT 1;";
//uso un archivo yml para la configuracion del cliente -- i use a yml file for the config of the client
var _connection = new MySqlConnection($"server={_config["SQLConnection:Server"]}; database={_config["SQLConnection:Database"]}; port={_config["SQLConnection:Port"]}; user={_config["SQLConnection:UserId"]}; pwd={_config["SQLConnection:Password"]}; ");
try
{
_connection.Open();
}
catch (Exception ex) { Console.WriteLine(ex); }
var Addtabletest = new MySqlCommand(command,_connection);
try
{
MySqlDataReader test = Addtabletest.ExecuteReader();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
Console.WriteLine("test");
}
edit:
i think i figured it out, the problem is the SELECT * i can get the individual or all of the fields i need but only if i name them
I don't want people to get connection string on error - example:
Try
{
// Some SQL code that fails
}
Catch (Exception sl)
{
MessageBox.Show("error - " + sl)
}
Is there a possibility that they could see connection string in exception sl? How can I avoid it? Also, they need to see error message, but without connection string.
I am using SQL Server.
Thanks for help!
I have written a function in my windows forms application that will return true or false based on the success in opening a connection to a database however my try catch block fails to catch the exception that is thrown.
private bool TestConnect()
{
try
{
conn.Open();
return true;
}
catch (OleDbException e) { return false; }
}
Error thrown:
System.Data.OleDb.OleDbException
Please help, I can not for the life of me figure this one out!
I figured it out, I needed to alert VS that I wanted to Except this error
I have this fragment of code:
Uri uri;
try {
uri = Windows.ApplicationModel.Store.CurrentApp.LinkUri;
}
catch(Exception ex) {
// exception is thrown
}
I get the exception:
ex = {System.Exception: The server machine is shutting down.
(Exception from HRESULT: 0x800704E7) at
Windows.ApplicationModel.Store.CurrentApp.get_LinkUri() at
MyApp.Controls.Screens.MainScreenControl..ctor()}
What does it mean and how can I avoid this exception?
The similar, unresolved question is here: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/6ebd1b23-b37b-4cc5-a840-d966527f7199/the-server-machine-is-shutting-down-exception-from-hresult-0x800704e7?forum=wpsubmit .
It looks like it was a temporary Windows Store server problem.
I'm having problems the in method create that is within a transaction and session Scope, because the table in the database has a trigger. Any suggestion?
This is the error I get:
An error occurred when trying to dispose the transaction
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Exception: An error occurred when trying to dispose the transaction
Obs.
If I remove the trigger, there is no error.
Code:
using (var session = new SessionScope())
{
try
{
using (Transaction = new TransactionScope(TransactionMode.New, OnDispose.Commit))
{
class.Create();
}
Transaction.VoteCommit();
}
catch (Exception ex)
{
Transaction.VoteRollBack();
throw new Exception(ex.Message);
}
}
I think the problem was the position of the using statement:
using (var session = new SessionScope())
{
using (Transaction = new TransactionScope(TransactionMode.New, OnDispose.Commit))
{
try
{
class.Create();
Transaction.VoteCommit();
}
catch (Exception ex)
{
Transaction.VoteRollBack();
throw new Exception(ex.Message);
}
}
}
you dispose Transaction before you can call Commit or Rollback.