循环通过webservices 获取一dateset,并循环dateset将数据插入到数据库中,但是插入一些数据后就报错,
请问是远程webservices的问题,还是本地数据库连接的问题
代码如下 a为webservices
for (int i = 0; i < dt.Rows.Count; i++)
{
ds = a.GetHotels(1, dt.Rows[i]["cityname"].ToString(), "");
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
string sql="insert into....";
}
try
{
SqlAccess.ExecuteNonQuery(sql1);
}
catch
{ }
}
错误提示:
基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Net.WebException: 基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。源错误: 行 82: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetHotels", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 83: public System.Data.DataSet GetHotels(int refId, string cityname, string hotelname) {
行 84: object[] results = this.Invoke("GetHotels", new object[] {行 85: refId,
行 86: cityname,
请问是远程webservices的问题,还是本地数据库连接的问题
代码如下 a为webservices
for (int i = 0; i < dt.Rows.Count; i++)
{
ds = a.GetHotels(1, dt.Rows[i]["cityname"].ToString(), "");
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
string sql="insert into....";
}
try
{
SqlAccess.ExecuteNonQuery(sql1);
}
catch
{ }
}
错误提示:
基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Net.WebException: 基础连接已经关闭: 服务器关闭了本应保持活动状态的连接。源错误: 行 82: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetHotels", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
行 83: public System.Data.DataSet GetHotels(int refId, string cityname, string hotelname) {
行 84: object[] results = this.Invoke("GetHotels", new object[] {行 85: refId,
行 86: cityname,
可能有两种情况:1.但是webservice连接不上数据库,测试在浏览器中输入webservice的url,然后找到GetHotels这个函数,传入参数,看是否能够调用成功。
2.GetHotels传入的参数是否有问题。
insert into table
select ... union all
....
select ...
然后操作
string sql="insert table(f1,f2)" ;
for(int i = 0; i < dt.Rows.Count; i++)
{
ds = a.GetHotels(1, dt.Rows[i]["cityname"].ToString(), "");
for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
{
if(j==ds.Tables[0].Rows.Count-1)
{
sql +="select ... union all";
}else
{
sql +="select ... "; }
}
}
try
{
SqlAccess.ExecuteNonQuery(sql);
}catch(Exception ee)
{
//....
}
ds = a.GetHotels(1, dt.Rows[i]["cityname"].ToString(), "");
这里放在循环里不如用in 把数据先取出来,然后拼接sql,再做SqlAccess.ExecuteNonQuery(sql1);
catch(Exception ee)
{
//....
}看看ee.Message显示的是什么
for (int i = 0; i < dt.Rows.Count; i++)
{
ds = a.GetHotels(1, dt.Rows[i]["cityname"].ToString(), "");
System.Threading.Thread.Sleep(2000);
for (int i = 0; i < dt.Rows.Count; i++)
{
int flag=1;
do
{
ds = a.GetHotels(1, dt.Rows[i]["cityname"].ToString(), "");
System.Threading.Thread.Sleep(2000*flag);
flag++;
}
while(ds!=null);
...
}