ASP.net,SQL Server,VWD 2010 [英] ASP.net,SQL Server,VWD 2010

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

问题描述

连接未关闭.连接的当前状态为连接中.
说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息.
异常详细信息:System.InvalidOperationException:连接未关闭.连接的当前状态为连接中.
源错误:

The connection was not closed. The connection''s current state is connecting.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The connection was not closed. The connection''s current state is connecting.
Source Error:

Line 30:             conn.my.Close();          
Line 31:         string SqlCmd = "select count(*) from Admin where UserName=''" + Login1.UserName+ "'' and PassWord=''" + Login1.Password+ "''";
Line 32:         conn.my.Open();
Line 33:         SqlCommand MyCmd = new SqlCommand(SqlCmd,conn.my);
Line 34:         int n = Convert.ToInt32(MyCmd.ExecuteScalar());



我该如何处理?我自己找不到任何错误.请帮我.非常感谢. :)



How can I deal with this problem?I can not find any errors by myself. Please help me. Many thanks. :)

推荐答案

已经在此处讨论了相同的问题 [ ^ ]


ExecuteScalar需要一个开放且可用的连接.该连接的当前状态为连接中.
说明:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪,以获取有关错误及其在代码中起源的详细信息.

异常详细信息:System.InvalidOperationException:ExecuteScalar需要打开且可用的Connection.连接的当前状态为连接中.

源错误:

ExecuteScalar requires an open and available Connection. The connection''s current state is connecting.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: ExecuteScalar requires an open and available Connection. The connection''s current state is connecting.

Source Error:

Line 34:         conn.my.Open();
Line 35:         SqlCommand MyCmd = new SqlCommand(SqlCmd,conn.my);
Line 36:   int n = Convert.ToInt32(MyCmd.ExecuteScalar());
Line 37:
Line 38:         if (n == 0)


当我在打开连接之前添加此行时:


When I added this line before opening a connection:

if(conn.State == ConnectionState.Closed)
cmdInsNew.Connection.Open();


它还没有工作.它仍然有一些错误.你能给我一些建议吗?非常感谢.:confused:


It did not work yet. It still has some errors. Could you give me some advise. Many thanks.:confused:


这篇关于ASP.net,SQL Server,VWD 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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