代码停止在DataAdapter.Fill行执行? [英] Code stops executing at DataAdapter.Fill line??

查看:73
本文介绍了代码停止在DataAdapter.Fill行执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,无法弄清楚为什么以下代码在标记的行(用***标记)上停止

hey guys, cant work out why the following code is stopping on the marked line (marked with ***)

...



namespace Keystore

{

public partial class FindKey : Form

{

public FindKey()

{

InitializeComponent();

}



DataSet ds;

System.Data.SqlClient.SqlDataAdapter da;

DatabaseHelper dataHelper = new DatabaseHelper();

DataRow dRow;



private void FindKey_Load(object sender, EventArgs e)

{

string sql = "SELECT * FROM Key";

string name = "AllKeys";

da = dataHelper.getAdapter(sql, name);

ds = dataHelper.getDataSet();



refreshList(1);

fillcboProvider();

fillcboProduct();



}



...



...



namespace Keystore

{



class DatabaseHelper

{

System.Data.SqlClient.SqlConnection con;

DataSet ds;

System.Data.SqlClient.SqlDataAdapter da;



public DatabaseHelper()

{

con = new System.Data.SqlClient.SqlConnection();

con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\KeyStore.mdf;Integrated Security=True;User Instance=True";

ds = new DataSet();

}



public System.Data.SqlClient.SqlDataAdapter getAdapter(String sql, String name)

{

da = new System.Data.SqlClient.SqlDataAdapter(sql, con);

da.Fill(ds, name); *** Code stops executing after here ***

return da;

}



... <br />

推荐答案

发生了什么事?它是挂起,引发异常还是以某种方式静默失败.

如果挂起,则连接字符串可能存在一些问题. SQL Server服务是否正在运行(在控制面板" \服务"中)?

另一种可能性是您的SELECT查询需要很长时间才能运行.如果您认为有可能,请在Management Studio中手动运行它,然后看看会发生什么.

What is happening?  Is it hanging, throwing an exception, or silently failing in some way.

If it is hanging, there is probably some problem with your connection string.  Is the SQL Server service running (in the Control Panel\Services)?

Another possibility is that your SELECT query is taking a long time to run.  If you think this could be a possibility, run it manually in Management Studio and see what happens.


这篇关于代码停止在DataAdapter.Fill行执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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