Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scope problem. Reuse SQL connection
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 1.1
OS:
Windows XP SP2
Network:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01016693
Message ID:
01016731
Views:
7
>The problem is that your oConnection property is not static and your methods trying to reference are static. As you probably know, static methods and properties can be accessed via the class without instantiating the object like this:
>
MainDQMClass.ListFiles(@"C:\Windows");
>Non static members can ONLY be accessed via an object (instantiated class) as in:
>
>MainDQMClass mdqmc = new MainDQMClass();
>mdqmc.Connection = new SQLConnection();
>
>If you want to stick with static methods, you'll either want to create and destroy the connection within each method (which I suspect you don't want to do), or add a connection parameter to all the static methods, create it in your calling code and pass it to each static method. Alternatively, you could make all your methods not static and just instantiate the class and it should run fine (which is maybe what your original intent was anyway).


That was it. You got the original intent right. I took out all the static declarations (which was I was somewhat confused on). Thanks!


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform