Reputation: 51
I'm running my WebApplication on IISServer.
I've created static class:
public class JMSInformationGetterUAT
{
private static String userName = "123";
private static String password = "321";
public static String runningJMS = "";
private static Admin adminConnection = null;
public static void Init()
{
try
{
String serverUrl = "tcp://localhost:1232";
adminConnection.CommandTimeout = 500;
adminConnection = new Admin(serverUrl, userName, password);
runningEMS = "JMS1Instance";
}
catch
{
EMSCriticalFailure = true;
}
}
}
and added it to Global.asax.cs:
protected void Application_Start(object sender, EventArgs e)
{
JMSInformationGetterUAT.Init();
}
... on page when I'm using JMSInformationGetterUAT.RunningJMS
I only get error:
"Object reference not set to an instance of an object".
On JMS side (that application is for quick monitoring) I see 1 ms connection and then none - but in object adminConnection
filled by Init()
method should keeping connection. Wen I refer to this object it is also empty...
So why this object is not persistent? It has static prefix...
please help me
Upvotes: 0
Views: 29
Reputation: 51
I've changed code a little after suggestion from Fran. Now it works:
public class JMSInformationGetterUAT{
private static String userName = "123";
private static String password = "321";
public static String runningJMS = "";
private static Admin adminConnection = new Admin("localhost:1234", userName, password);
public static void Init()
{
//some other logic i needed
} }
Upvotes: 0
Reputation: 6530
You are setting a the property CommandTimeout of the adminConnection before you instantiate new Admin.
adminConnection = new Admin (...)
needs to occur before you can access any non static properties.
Upvotes: 2