C#接続sql server 2008の1件2件


once upon a time, i came upon one thing that my c# program cannot access its specified database which sql server 2008. i dont know why, at my point of view, the program works well for sql server 2000, now it doesn't work for 2008, it's mainly supposed to be the cause of the new database, maybe they have different connection ways. At the thought of this, i began to search a lot about how to connect to 2008, with a result you can imagine, all failed. my class design is like the follows:
 
public class Service : System.Web.Services.WebService

{

    private static string connectionString = "";

    [WebMethod]
    public string WebserviceCrud(string strxml)

    {

        //connectionString = "SERVER=" + databaseip + "," + databaseport + ";DATABASE=" + databasename + ";Uid=" + userid + ";pwd=" + password;
        //connectionString = "Data Source=" + databaseds + "," + databaseport + ";Initial Catalog=" + databasename + ";Persist Security Info=True;User Id=" + userid + ";Password=" + password + ";";
        connectionString = "data source=" + databaseds + ";initial catalog=" + databasename + ";user id=" + userid + ";password=" + password + ";";

        return InvokeMethod(methodname, mParam);

    }


    public string InvokeMethod(string methodname, object[] mParam)
    {
        // Create MyClass object
        Service myClassObj = new Service();
        // Get the Type information.
        Type myTypeObj = myClassObj.GetType();
        // Get Method Information.
        MethodInfo myMethodInfo = myTypeObj.GetMethod(methodname);

        return (string)myMethodInfo.Invoke(myClassObj, mParam);
    }

    public string RequestUserQuery(string parameters)
    {
        string username = xmlhandle.GetNodeContent(parameters, "/Params/UserId");

        string commandText = "SELECT STAFF_ID as StaffId, isnull(STAFF_NAME, 'null') as StaffName, isnull(JOB, 'null') as Job, DEPT_NO as DeptNo FROM WHS_STAFF WHERE LOGIN_USERNAME = '" + username +"'";
        DataSet ds = OnlineShop.Database.SqlHelper.ExecuteDataset(connectionString, CommandType.Text, commandText);

        string xml = ds.GetXml();

        xml = xml.Replace("<NewDataSet>", "<Results>");
        xml = xml.Replace("</NewDataSet>", "</Results>");
        xml = xml.Replace("<Table>", "");
        xml = xml.Replace("</Table>", "");

        return GenerateResponseXml("ResponseUserQuery", xml);
    }

}
 
as you see, the connectionString's not static at the first place, so with every call of webmethod, it creates every new object, thus every new member field connectionString, even though i've changed its value, it's just acts as if it didn't change at all, it holds the original value from its declaration.
 
why can't i find this error? i concluded it's all from mindset . as i dont think the other part may have errors. as it just has been working fine before, cause i forgot the truth i ever modifed it the day before but i didn't check it through. it's really a lesson which deserves to be tight remembered.