从Sql Server数据库中选择数据时出现问题 [英] Problem while selecting Data from Sql Server database

查看:105
本文介绍了从Sql Server数据库中选择数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我遇到一个问题,从empdetails选择*"可以正常工作,但是从empdetails选择empName,其中empId ="sumit"和password ="12345''"需要更多的时间,之后会出现异常消息"ExecuterReader"需要一个开放且可用的连接.该连接的当前状态为关闭."

我在Web服务器上触发了这些命令(在我的本地PC上,两个命令都运行正常).

请帮帮我.

Hi Guys,

I am facing a problem, "select * from empdetails" working fine but "select empName from empdetails where empId=''sumit'' and password=''12345''" it takes much more time and after that gives exception message "ExecuterReader requires an open and available Connection. The Connection''s current state is closed."

i fire these command on web server( on my local pc both command working fine).

Please help me.

Thank you in advance!

推荐答案

在ExecuteReader()之前

试试这个

sqlconnection.Open();
Before ExecuteReader()

try this

sqlconnection.Open();


SqlConnection con =新的SqlConnection("Server =(local)\\ SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = SSPI");

SqlCommand cmd =新的SqlCommand();

cmd.CommandText ="SELECT EmployeeID,FirstName +``''+ LastName作为来自员工的FullName";

cmd.Connection = con;

SqlConnection con = new SqlConnection("Server=(local)\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI");

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "SELECT EmployeeID, FirstName + '' '' + LastName as FullName FROM Employees";

cmd.Connection = con;

if (con.State == System.Data.ConnectionState.Open)
        {
            con.Close();
        }



con.Open();

SqlDataReader reader = cmd.ExecuteReader();

while(reader.Read()){

}

reader.Close();
con.Close();




还请检查下面的链接
http://forums.asp.net/post/4623355.aspx [



con.Open();

SqlDataReader reader = cmd.ExecuteReader();

while (reader.Read()) {

}

reader.Close();
con.Close();


or

also check below link
http://forums.asp.net/post/4623355.aspx[^]


这篇关于从Sql Server数据库中选择数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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