I am using AdomdConnection connection class to connect to the Cube. I am using following code.
using (var conn = new AdomdConnection(ConnString))
{
conn.Open();
var cube = conn.Cubes[name];
//Do something
conn.Close();
}
AdomdConnection.ConnectionTimeout Property does not have setter property.
The default value for connectionTimeOut property is 0, which sets the time to infinite.
I have two questions:
Is there any way to set the timeout property for AdomdConnection?
When the cube is busy and your try to run the program, after creating the connection when you open the connection (conn.open()), system does not come out of this statement & never executes the next line of code. In such cases the application becomes irresponsible and there is no exception thrown. How can I inform user about such scenarios & make a log entry.
I looked into this similar tread but did not found it useful.
Thank you
The documentation states this for AdomdConnection.ConnectionTimeout
Gets the time to wait for a connection to be established before the
AdomdConnection stops trying to connect and generates an error.
So that means the timeout just talking to the server.
If you want a timeout when your running an actual command use the AdomdCommand.CommandTimeout property.
Gets or sets the time to wait for a command to run before the
AdomdCommand stops trying to run the command and generates an error.
Both can be set with the connection string.
http://msdn.microsoft.com/en-us/library/microsoft.analysisservices.adomdclient.adomdconnection.connectionstring.aspx
Related
I'm trying to kill query triggered by ADO.NET command on postgresql database, after command timeout:
using (var command = new PgSqlCommand("public.timeout_test", connection))
{
command.CommandTimeout = 10;
command.CommandType = CommandType.StoredProcedure;
connection.Open();
command.ExecuteNonQuery();
}
In dotnet code timeout exception is being throwed correctly, but I wonder why query triggered by timout_test function is still in active state. If I run below query, then query executed by timeout_tets is listed as active:
SELECT * FROM pg_stat_activity where state = 'active';
Tried to test it with devart and npgsql connectors, but both of them behave in the same way, so I assume that it's intended behevior, but don't understand the reason. Also wanted to ask if there is a way to kill query after command timeout.
At least in Npgsql, CommandTimeout is implemented as a client-side socket timeout: after a certain amount of time Npgsql will simply close the network socket on its side. This doesn't cancel the query server-side, which will continue running.
You can set the PostgreSQL statement_timeout parameter to have it kill queries running more than a given amount of time; for best results, set statement_timeout to something lower than CommandTimeout - this will ensure that server timeout occurs before client timeout, preserving the connection and transmitting the server timeout to the client as a regular exception.
Another option is to manually trigger a cancellation from the client by calling NpgsqlCommand.Cancel(). You can do this whenever you want (e.g. when the user clicks a button), but contrary to statement_timeout it will obviously work only if the network is up.
I have class (let's call it DbHostWindows) that contains various things about a windows server. I make an instance of this whenever I want to do something remotely on the server. One of the things this class consist of is a WsManConnection - this is part of the constructor:
vWinRM = new WsManConnection(vServerName);
public WsManConnection(string wsManHostName) {
vWsManConnectionInfo = new WSManConnectionInfo(new Uri($"http://{wsManHostName}:5985/wsman")) {
OpenTimeout = WsManDefaultTimeoutInMs,
OperationTimeout = WsManDefaultTimeoutInMs,
IdleTimeout = WsManIdleTimeoutInMs
};
Init();
}
I have noticed that whenever I run the DbHostWindows constructor I get a wsmprovhost.exe process running on the server.
"C:\windows\system32\wsmprovhost.exe -Embedding"
I also noticed that the default timeout of such a process apparently is around 24 days. Setting IdleTimeout to 60000 (minimum value) reduce the timeout to a minute.
My problem is that I would like to get rid of the wsmprovhost.exe process earlier than a minute - in fact as soon as I dispose of the DbHostWindows object and hence the WsManConnectionInfo. I know at this point I will never use this connection again. I can't figure out how to do this, however.
For testing purposes I tried adding these commands in the end of the constructor in order to try and kill it asap and being sure the connection wasn't used for anything:
vWinRm.PowerShell.Stop();
vWinRm.PowerShell.Runspace.Disconnect();
vWinRm.PowerShell.Dispose();
vWinRm.Dispose();
Neither seem to affect the wsmprovhost.exe process at all. The wsmprovhost.exe does close after the IdleTimeout is up. As a workaround I could just raise the MaxProcessesPerShell on the server, but I would rather get these processes to close when the DbHostWindows is disposed.
I am having some problems to handle the connection to a database. What I did essentially was to create a class called Database, in this I placed all the methods required to connect to the database, check whether the connection is active and update a control depending on the status of the connection. This works well, control is updated and there are no problems, but when the connection on your computer is absent, the program delays its opening because they generated a series of exceptions in particular that:
MySql.Data.MySqlClient.MySqlException (0x80004005)
The exception occurs in the method isAvailable(), this method checks whether the connection is available or not, and returns true if there is, respectively, or false if it is absent.
public static bool isAvailable()
{
try
{
string connStr = #"Server=xxx;Port=xxx;Database=xxx;Uid=xxx;Pwd=xxx;";
connection = new MySqlConnection(connStr);
connection.Open();
return true;
}catch(Exception ex)
{
connection.Close();
Console.WriteLine(ex.ToString());
return false;
}
}
This method is invoked by checkStatus that contains the following:
public static void checkStatus()
{
if(isAvailable() == false)
{
updateStatus("false");
}
else
{
updateStatus("true");
}
}
checks whether it is true or false and returned respectively to the back passes the value to another method that simply brings up a warning Canvas red or green in the interface ...
checkStatus is called in every aspect of my other classes to check the connection status (before executing a query, pretty much the structure is as follows):
string stm = "SELECT * FROM history";
MySqlCommand cmd = new MySqlCommand(stm, Database.Database.Connection);
Database.Database.checkStatus(); //here
MySqlDataReader rdr = cmd.ExecuteReader();
Within the class constructor call the method isAvailable Database to check if the connection is actually open or not.
At this point I do not understand why the exceptions while managing the program delays the appearance when the user executes it. If no exceptions occur when you start, the program takes about 5 seconds to boot, while with the exceptions I arrived at 1 minute!
What am I doing wrong?
Making a connection to the database server may take quite some time due to many factors: network conditions, server load, authentication overhead etc. Hence the driver (the code behind MySqlConnection) needs to wait an appropriate amount of time to decide whether the connection can or cannot be established. The default timeout is, apparently in your case, 60 seconds (or a multiple of the default 15 seconds as per documentation due to several requests?).
What you can do is lower the timeout by means of the ConnectionTimeout argument in the connection string — see the documentation here. However, bear in mind that by setting it to, say, 5 seconds, you program may end up failing in legitimate cases where it would otherwise succcessfuly connect to the server. I suggest you perform database operations or at least the initial check asynchronously and display a 'please wait' message meanwhile.
i have database query: datareader.execQuery("select * from table");
However sometimes database takes too long to respond and is stuck at this line.
if this happens my application should exit
Thanks guys but i need to know:
Is there any way i can achieve this using Stopwatch or Timer??
You should set the CommandTimeout on your SqlCommand object. If the timeout is exceeded, you will get an exception. You can catch this, and exit your app, if that is what you want to do.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx
"Gets or sets the wait time before terminating the attempt to execute a command and generating an error."
A cleaner way will be to set the SqlCommand.CommandTimeout property by default it is 30 secs
You will have to handle the TimeOut Exception
I am developing a .NET web application with C# and SQL Server as database, being newbie for both technologies. I have a problem when I attempt to save a lot of information at the same time.
My code is simple:
SqlConnection cn = null;
try
{
using (TransactionScope scope = new TransactionScope())
{
using (cn = Util.getConnection())
{
cn.Open();
BusinessObject.saveObject1(param1, cn);
BusinessObject.saveObject2(param2, cn);
BusinessObject.saveObject3(param3, cn);
BusinessObject.saveObject4(param4, cn);
...
scope.Complete();
}
}
I always use the same connection object because if an error happens, I must revoke any change in my data and the same behaviour if the process is ok, is needed.
I don't mind it the process of saving takes a lot of time, in my application is perfectly normal because I have to save a lot of information.
The weirdness here is:
When I execute this function in the same local area network of the database, it perfectly works.
However, if I execute it from outside, such as, connected by a VPN and consequently with higher latency, I get an error with the message: "The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements."
I have tried to change the timeout of the database through the connection string in the web.config but it didn't resolve anything. Also, if after each executeNonQuery() statement I do a cn.Dispose(), I get an error in the next attempt to use the connection object.
Do I have to change the parameters of TransactionScope object? Is there another better way to do this?
Thanks in advanced.
This is due to a timeout error. The TransactionScope might decide to rollback the transaction in case of a timeout.
You need to increase the timeout value in the TransactionScope constructor. The default max. timeout is 10min.
Move scope.Complete(); outside the connection block (MSDN article).
Did you try setting the Timeout = 0 in your Util.getConnection() function ? A value of 0 indicates no limit. This will complete the job surely. By setting the Timeout = 0 will complete every long operation job.