Problem in accessing Application variable
-
hi all, I have created an Application level connection string variable in my Global.asax Like: Application("glbConnection") = con.getDBConnection() I accessed that variable in My Business class like, con As IDbConnection = Application("glbConnection") But i Got the Error as , System.NullReferenceException {"Object reference not set to an instance of an object."} Message : "Object reference not set to an instance of an object." I need to access my application variable in my Class file. can anyone help me out to solve this problem Thanks in advance. Regards senthilraj K
-
hi all, I have created an Application level connection string variable in my Global.asax Like: Application("glbConnection") = con.getDBConnection() I accessed that variable in My Business class like, con As IDbConnection = Application("glbConnection") But i Got the Error as , System.NullReferenceException {"Object reference not set to an instance of an object."} Message : "Object reference not set to an instance of an object." I need to access my application variable in my Class file. can anyone help me out to solve this problem Thanks in advance. Regards senthilraj K
-
hi all, I have created an Application level connection string variable in my Global.asax Like: Application("glbConnection") = con.getDBConnection() I accessed that variable in My Business class like, con As IDbConnection = Application("glbConnection") But i Got the Error as , System.NullReferenceException {"Object reference not set to an instance of an object."} Message : "Object reference not set to an instance of an object." I need to access my application variable in my Class file. can anyone help me out to solve this problem Thanks in advance. Regards senthilraj K
To solve your current problem : I guess con.getDBConnection() returns a null value To solve your next problem, I don't think you want to connect to your database throughout your website this way. You say you have a business class. The business class should be in a separate project (your business project) which contains all db functionality and stuff and returns the required information to your user interface (in this case a website). In theory, you're website shouldn't be able to 'know' your connection string.
.: I love it when a plan comes together :. http://www.zonderpunt.nl
-
To solve your current problem : I guess con.getDBConnection() returns a null value To solve your next problem, I don't think you want to connect to your database throughout your website this way. You say you have a business class. The business class should be in a separate project (your business project) which contains all db functionality and stuff and returns the required information to your user interface (in this case a website). In theory, you're website shouldn't be able to 'know' your connection string.
.: I love it when a plan comes together :. http://www.zonderpunt.nl
i am getting the connection string in my code behind file when i use the appliaction variable (webform1.aspx.vb) When i try this with my class i am getting the error. Do i need to import any namespace in my class file to access this application variable in my class?? thanks, Senthilraj K
-
i am getting the connection string in my code behind file when i use the appliaction variable (webform1.aspx.vb) When i try this with my class i am getting the error. Do i need to import any namespace in my class file to access this application variable in my class?? thanks, Senthilraj K
-
i am getting the connection string in my code behind file when i use the appliaction variable (webform1.aspx.vb) When i try this with my class i am getting the error. Do i need to import any namespace in my class file to access this application variable in my class?? thanks, Senthilraj K
Erhm, in this case, you can better create a function which connects to the database for you in your businessfile
public void ConnectDb(object ConnectionString) { if (ConnectionString == null) return; con = new con(ConnectionString.ToString()); }
and call that function from your webpageConnectDb(Application["yourvariable"]);
.: I love it when a plan comes together :. http://www.zonderpunt.nl
-
hi navaneeth, i tried with your option.but, when i try to type the Context.Application i am getting the error as 'Context' is not accessible. I have imported the 'System.Web.HttpContext' in my class.but still getting the error.... do you have any sample code to do this???? thanks, Senthilraj K
-
hi all, I have created an Application level connection string variable in my Global.asax Like: Application("glbConnection") = con.getDBConnection() I accessed that variable in My Business class like, con As IDbConnection = Application("glbConnection") But i Got the Error as , System.NullReferenceException {"Object reference not set to an instance of an object."} Message : "Object reference not set to an instance of an object." I need to access my application variable in my Class file. can anyone help me out to solve this problem Thanks in advance. Regards senthilraj K
For security reasons you should define your connection strings in web.Config, and access then using the ConfigurationManager.ConnectionStrings[^] properties
Cheers, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
-
For security reasons you should define your connection strings in web.Config, and access then using the ConfigurationManager.ConnectionStrings[^] properties
Cheers, Mircea Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
But using web.config for only a connectionstring isn't really the neat way, because handling a web.config is relatively pretty time consuming...
.: I love it when a plan comes together :. http://www.zonderpunt.nl