What are the potential problems using this static class

Here is my sample code:

public static class MySqlHelper
{
    private static string constring = ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;

    public static int ExecuteNonQuery(string mysqlquery)
    {
        SqlConnection conn = new SqlConnection(connString);
        SqlCommand cmd = new SqlCommand(mysqlquery, conn);
        int result;

        try
        {
            conn.Open();
            result= cmd.ExecuteNonQuery();
        }
        finally
        {
            conn.Close();
        }
        return result;
    }
}

Using: MySqlHelper.ExecuteNonQuery("select * from customers");

I would like to know the problems using this static class.

I can change my class as mentioned here , but I have used this class in several websites and it will take me a couple of days to change it in all places and check this out.

Thanks for any inputs.

Edit: Updated code. Does this mean that answers are provided? Sorry, I should have published at the beginning.

+3
source share
7 answers

, ( ). , .

, - , . , .

, : .

+6

, .

ASP.NET

", , ..."

+4

.

, -. - , .

. .

+2

, , , factory, , , , execereader other mthods, . , , , executereader, , - ,

+1

:

  • ://open conn +//close conn

1) ,

2) : .. .

+1

, MySQL Connector .NET MySqlHelper ( )?

0

, Microsoft DAAB SqlHelper v2. , . SqlParameters. 2001 .

http://www.microsoft.com/download/en/details.aspx?id=435

0

All Articles