C
craigclister
I'm writing a small 'learning' app. It uses SQL Server.
I am trying to create a common class of database functions. So, am I
right in saying that it should be a static class? I've done that, but
then I can't declare a private class variable, because the class is
static...
internal static class Database
{
internal SqlConnection conn = new SqlConnection(); <---
Error...
internal static bool Connect()
{
try
{
conn.ConnectionString = "Data Source=localhost;
Integrated Security=SSPI; Initial Catalog=HomeShopper";
conn.Open();
return true;
}
catch(Exception e)
{.................................
How should I be doing this? I'd like to then be able to:
Common.Database.Connect();
I am trying to create a common class of database functions. So, am I
right in saying that it should be a static class? I've done that, but
then I can't declare a private class variable, because the class is
static...
internal static class Database
{
internal SqlConnection conn = new SqlConnection(); <---
Error...
internal static bool Connect()
{
try
{
conn.ConnectionString = "Data Source=localhost;
Integrated Security=SSPI; Initial Catalog=HomeShopper";
conn.Open();
return true;
}
catch(Exception e)
{.................................
How should I be doing this? I'd like to then be able to:
Common.Database.Connect();