C#连接存储过程错误

时间:2017-10-23 08:27:50

标签: c# mysql

此代码正在建立Mysql连接。

namespace TrialConnection
    {
        public class DataConnection
        {
            public static string database = "";
            public static string databasename = "";
            public static string user = "";
            public static string password = "";
            public static string charset = "latin1";


        string connString = "";

        public DataLayer(ref MySqlCommand newconnection)
        {
            connString = "On server = " + database + "; Databasename = " + databasename + "; User = "
                + user + "; Pass = " + password + "; Locale = " + charset; 

            newconnection = new MySqlCommand();
        }

        public bool modifyData(ref MySqlCommand newconnection, Alter_Procedures myQuery)
        {
            MySqlConnection myconnection = new MySqlConnection(connString);
            newconnection.Connection = myconnection;
            newconnection.CommandText = modifyQuery.ToString();
            newconnection.CommandType = CommandType.StoredProcedure;
            MySqlTransaction mytransaction = null;

            try
            {
             myconnection.Open();
     mytransaction = myconnection.BeginTransaction();
             newconnection.Transaction = mytransaction;
             newconnection.ExecuteNonQuery(); 
             mytransaction.Commit();
             mytransaction.Dispose();
             myconnection.Close();
             myconnection.Dispose();
            }catch(Exception e){}
        }

        public bool getData(ref MySqlCommand newconnection, Retrieve_Procedures allproc, ref MySqlDataReader myReader)
        {
            MySqlConnection myConnection = new MySqlConnection(connString);
            newconnection.Connection = myConnection;
            newconnection.CommandType = CommandType.StoredProcedure;
            newconnection.CommandText = allproc.ToString();

            myConnection.Open();
            myReader = newconnection.ExecuteReader();
        }

    }
}

每当我尝试连接并且数据库中还没有存储过程时,它并不总是采用我的数据库,数据库名,用户,密码和字符集的值。

我试图调试它并找到了一些东西,但是我不确定我是否找到了所有东西。

我非常感谢您的帮助。

0 个答案:

没有答案