Windows form global object
-
Hi, I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this? Ps. The connection object instantiated on login should be visible throughtout the entire application.
-
Hi, I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this? Ps. The connection object instantiated on login should be visible throughtout the entire application.
datastruct wrote:
I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this?
What you actually want to do is create a DAL (Data Access/Abstraction Layer) class (or classes). The DAL is either going to be a singleton or a static class. Here is a very basic example:
public static Dal
{
private static SqlConnection theConnection;public static ConnectionString { set { theConnection = new SqlConnection(value) } } public static DataSet SomeQuery(int id) { // Write the code to perform the query here. }
}
-- modified at 6:50 Saturday 4th August, 2007 (Corrected code)
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
datastruct wrote:
I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this?
What you actually want to do is create a DAL (Data Access/Abstraction Layer) class (or classes). The DAL is either going to be a singleton or a static class. Here is a very basic example:
public static Dal
{
private static SqlConnection theConnection;public static ConnectionString { set { theConnection = new SqlConnection(value) } } public static DataSet SomeQuery(int id) { // Write the code to perform the query here. }
}
-- modified at 6:50 Saturday 4th August, 2007 (Corrected code)
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
You forgot to make somequery static :p
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Hi, I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this? Ps. The connection object instantiated on login should be visible throughtout the entire application.
Create one Singleton class. This should have a member of type "OdbcConnection" The connection to the database should be stablished in the constroctor of this class. This class should have a member function to return the object of type "OdbcConnection".
Manoj Never Gives up
-
You forgot to make somequery static :p
Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Christian Graus wrote:
You forgot to make somequery static
:-O Oops!
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
Create one Singleton class. This should have a member of type "OdbcConnection" The connection to the database should be stablished in the constroctor of this class. This class should have a member function to return the object of type "OdbcConnection".
Manoj Never Gives up
Manoj Kumar Rai wrote:
This class should have a member function to return the object of type "OdbcConnection".
Why an OdbcConnection?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
datastruct wrote:
I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this?
What you actually want to do is create a DAL (Data Access/Abstraction Layer) class (or classes). The DAL is either going to be a singleton or a static class. Here is a very basic example:
public static Dal
{
private static SqlConnection theConnection;public static ConnectionString { set { theConnection = new SqlConnection(value) } } public static DataSet SomeQuery(int id) { // Write the code to perform the query here. }
}
-- modified at 6:50 Saturday 4th August, 2007 (Corrected code)
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
Thanks pal.It did solve my issue.