连接问题 [英] Problem with connection

查看:83
本文介绍了连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Winform C#程序,当我从mysql表中填充Combobox时,但我在组合代码中添加了一个空行或者mysql中的表。当我点击保存底部它告诉我与数据库的连接尚未关闭我已检查并关闭它在许多不同的方式,它只是不会工作,但如果我采取空行它将工作没有问题(我需要空行)。



如果有人可以帮我请。



对不起,这里是填充组合框的代码



Hi,

im working on a Winform C# program and when i populate Combobox from mysql table, but i added a blank line to the combo throu code or on the table in mysql. and when i click save bottom it tells me that the connection to the database has not been closed i have check and close it on many diferent way and it just wont work, but if i take the blank line it would work with no problem (i need the blank line).

if any body can help me please.

Sorry, here is the code for populating the combobox

private void cargacombocs(string bsc)
        {
            try
            {                

                MySqlCommand cmd = Form2.conecxionsyscon.CreateCommand();

                MySqlDataReader Reader;
                
                cmd.CommandText = "SELECT subcatp FROM budcatpaf WHERE indpp = '" + bsc + "'";

                Form2.conecxionsyscon.Open();
                Reader = cmd.ExecuteReader();
                while (Reader.Read())
                {
                    string thisrow = "";
                    for (int i = 0; i < Reader.FieldCount; i++)
                        thisrow += Reader.GetValue(i).ToString();
                    comboBox2.Items.Add(thisrow);
                    comboBox3.Items.Add(thisrow);
                    comboBox8.Items.Add(thisrow);
                }
                
            }
            catch (MySqlException ex2)
            {
                MessageBox.Show("Code: " + ex2.Message);
            }
            Form2.conecxionsyscon.Close();
        }





这是保存到mysql中的一个表,保存后打开一个带有一些信息的水晶报告

但在它打开水晶之前我收到错误消息,表明coneccion仍然打开



这是我创建连接的地方





this is save to a table in mysql which after saving opens up a crystal report with some info
but before it opens the crystal i get the error message that the coneccion is still open

This is where i create the conection

MySqlConnectionStringBuilder connBuilder = new MySqlConnectionStringBuilder();

                connBuilder.Add("DataBase", srv[1]);
                connBuilder.Add("Data Source", srv[0]);
                connBuilder.Add("User Id", srv[2]);
                connBuilder.Add("Password", srv[3]);
                                
                conecxionsyscon = new MySqlConnection(connBuilder.ConnectionString);
                
                MySqlCommand cmd = conecxionsyscon.CreateCommand();

推荐答案

你好

我检查了你的代码,我发现在catch块中你也需要关闭sql连接,在打开新连接时你需要检查现有连接是否打开。
Hello
I have checked your code and i found that in catch block also you need to close sql connection and while opening new connection you need to check whether existing connection is open.


这篇关于连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆