1。是可以的,可以放在Config中,但是建议你最好建立一个属性,将数据库连接字符串作为一个类的变量.
2.不用重新打包
3.webservice支持结构传参,因为它用的是SOAP作为底层协议.可以跨越防火墙.大Dataset同理
4.用引用后要NEW一个它的实例
  DataSet ds1= new dataset;
  就行.
  不用using 
  service_report.service_report a = new service_report.service_report()

解决方案 »

  1.   

    楼上回答得很祥细了,
    1、在Web.Config里
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <appSettings>
           <add key="ConnStr"value="server='sms';uid='test';pwd='xxx';database='data';"/>
         </appSettings>
        
      <system.web>
    …………
      

  2.   

    To
    3---说说程序中引用web service的问题.
        命名空间:service_report   
        有:report_dll类
        有方法: search_report_sqwxdj  
        通过传递一个参数,返回一个dataset 类型的值.using sw001.report_search;     // 这句引用需要吗?
    应该是
    using sw001; 
    相应的new,应该改为
    service_report a = new service_report();
    如果返回不是标准类型的数据,应该用object来接收,
    所以
    object objDB=a.search_report_sqwxdj();
      

  3.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using sw001.report_search;  namespace sw001
    {
    /// <summary>
    /// sw001_report_sqwxdj 的摘要说明。
    /// </summary>
    public class sw001_report_sqwxdj : System.Web.UI.Page
    {
    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
    report_search.report_dll ser=new report_search.report_dll();
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    string param_string=Request.QueryString["param"].ToString();
    DataSet dsds=new DataSet();
    dsds=ser.search_report_sqwxdj(param_string);       //出错........
    reprot.report_sqwxdj rp_sqwxdj=new reprot.report_sqwxdj();
    rp_sqwxdj.SetDataSource(ds1);
    this.CrystalReportViewer1.DisplayToolbar=false;
    this.CrystalReportViewer1.DisplayGroupTree=false;
    this.CrystalReportViewer1.ReportSource=rp_sqwxdj;
    }
    }
    在客户端调用是出错...
    DataSet dsds=new DataSet();
    dsds=ser.search_report_sqwxdj(param_string);请求因 HTTP 状态 401 失败:Access Denied。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Net.WebException: 请求因 HTTP 状态 401 失败:Access Denied。
    为什么???
      

  4.   

    单独运行(调试)
    web service (http://localhost/service_report/report_dll.asmx)
    没有问题
      

  5.   

    这句
    dsds=ser.search_report_sqwxdj(param_string);       

    ser初始化了吗?
      

  6.   

    一般些Client程序调用WebService,基本步骤如下:
    1.web引用webservice;系统会自动创建一个类,一般如:机器名.服务名;
    2.用上面引用过来的类来定义变量;
    3.用此变量来访问相应的web方法。
      

  7.   

    ser初始化:
    report_search.report_dll ser=new report_search.report_dll();
      

  8.   

    其实我最近也写了一个关于WebService的一个项目,也用到对数据库的操作,但我一般不返回DataSet类型(也没去试过),我的做法是定义一个struct,大量数据用其的ArrayList返回。对于在soap中返回的信息是否真的能再组成DataSet产生怀疑。我觉得不可以,返回一个类的对象,不仅仅是数据,还有相关的方法等等,而后者在soap中是很难的。
      

  9.   

    很奇怪
    我在家里用web service来接收的返回值dataset没有问题,客户端运行没有一点问题.
    可是拷贝到办公室来,一执行就出现以下的错误:"请求因 HTTP 状态 401 失败:Access Denied。 "
     说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该 错 误以及代码中导致错误的出处的详细信息。  异常详细信息: System.Net.WebException: 请求因 HTTP 状态 401 失败:Access Denied。这是为什么???还有生么地方需要设置吗??
      

  10.   

    1、确认一下能否在IE中运行你的程序,不是debug状态,即在IE的地址栏中输入你的WebService的名称,调用你所出错的函数,看看会不会生成结果集;2、检查ASPNET用户的权限;3、检查连接数据库的参数;//最好用数据库的用户名和密码
      

  11.   

    to  Knight94(愚翁):
       首先谢谢你的多次指点.
       我想是权限的问题:
       现在别人在ie栏中输入我的aspx程序名,总是提示要输入用户及密码...
       我不知道还有哪里需要配置.....iis中设置了允许匿名用户访问. 
    还有什么地方需要设置的吗???
      

  12.   

    to  Knight94(愚翁):  1- 在ie中运行web service没有问题.输入相应的参数也可以生成相应得到数据集.DataSet ds;
    private SqlConnection con;[WebMethod]
    public DataSet search_report_gcbl(string param,int flg_year_month)
    {
    string strcon="server=cad097;uid=*;pwd=*;database=sv001";
    string year_param="",month_param="";
    year_param=param.Substring(0,4).ToString();   
    con=new SqlConnection(strcon);
    string strsql="";
    if (flg_year_month==1)
    {
    month_param=date_month(param);
    strsql+="and month(xldate)='"+ month_param+"'  ";
    }
    if (flg_year_month==2)
    { strsql=strsql; }
    con.Open();
    SqlDataAdapter da=new SqlDataAdapter(strsql,con);
    ds=new DataSet();
    da.Fill(ds,"t_sqwxdj");
    con.Close();
    return ds;
    }出现以下的错误...
    "System.InvalidOperationException: ExecuteReader:CommandText 属性尚未初始化
       at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
       at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
       at service_report.report_dll. search_report_gcbl(String param, Int32 flg_year_month)"
      

  13.   

    你先把ASPNET用户加到administrators中,看是否可以?(不一定非要这样,因为我的系统是win2000server就没不需要这样,但有的机器就需要,我再看看资料,查查是否有替代的方法)如果还不行的话,进行单步debug。用vs.net运行你的程序,在相应的位置设置断点;再用Client去调用,看看进入断点后,具体是哪句话出错了,从而找出真正的错误。
      

  14.   

    单独运行web service 没有问题,可以生成dataset
        但是从客户端调用web service的时候还是出现以下的错误,(在家中做的时候没有问题,copy到办公室来就出问题..)   "请求因 HTTP 状态 401 失败:Access Denied。 "
        说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该 错 误以及代码中导致错误的出处的详细信息。 
        异常详细信息: System.Net.WebException: 请求因 HTTP 状态 401 失败:Access Denied。
         是不是还有什么地方需要配置...
      

  15.   

    真的没有人知道原因吗?
    行 165:[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/search_report_zztj", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]行 166: public System.Data.DataSet search_report_zztj(string param, int flg_year_month) {行 167: object[] results = this.Invoke("search_report_zztj", new object[] {行 168:  param,行 169:  flg_year_month});
      

  16.   

    [WebMethod]//售前维修登记
    public DataSet search_report_sqwxdj(string param,int flg_year_month)
    {
    string strcon="server=172.17.96.97;uid=sa;pwd=l;database=sv001";
    string year_param="",month_param="";
    year_param=param.Substring(0,4).ToString();   
    con=new SqlConnection(strcon);
    string strsql="SELECT t_sale.model AS model, t_sale.jh AS jh, t_sale.kxdate AS kxdate,"
    +" t_sale.xldate AS xldate, t_zz.zzname AS zz, "
    +"t_yy_lb.lbname + t_yy_nr.nrname + t_yy_jg.jgname AS yy, "
    +"t_fsd.fsdname AS fsdname  "
    +" FROM t_yy_lb INNER JOIN  t_salezz INNER JOIN "
    +" t_sale ON t_salezz.saleid = t_sale.saleid INNER JOIN "
    +" t_zz ON t_salezz.zzdm = t_zz.zzdm INNER JOIN "
    +" t_saleyy ON t_sale.saleid = t_saleyy.saleid INNER JOIN "
    +" t_fsd ON t_sale.fsddm = t_fsd.fsddm INNER JOIN "
    +" t_yy_jg ON t_saleyy.jgdm = t_yy_jg.jgdm AND "
    +" t_saleyy.lbdm = t_yy_jg.lbdm INNER JOIN "
    +" t_yy_nr ON t_saleyy.lbdm = t_yy_nr.lbdm AND t_saleyy.nrdm = t_yy_nr.nrdm ON "
    +" t_yy_lb.lbdm = t_saleyy.lbdm "
    +" where year(xldate)='"+ year_param +"' and saleflg='1'";
    if (flg_year_month==1)
    {
    month_param=date_month(param);
    strsql += "and month(xldate)='"+ month_param+"'" ;
    }
    if (flg_year_month==2)
    {   strsql=strsql; }
    con.Open();
    SqlDataAdapter da=new SqlDataAdapter(strsql,con);
    ds=new DataSet();
    da.Fill(ds,"t_sqwxdj");
    con.Close();
    return ds;
    }
      

  17.   

    string strsql="";
    if (flg_year_month==1)
    { month_param=date_month(param);
    strsql+="and month(xldate)='"+ month_param+"'  ";
    }
    if (flg_year_month==2)
    { strsql=strsql; }
    con.Open();
    SqlDataAdapter da=new SqlDataAdapter(strsql,con);
    你的strsql没有语句啊!
      

  18.   

    cs代码
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    using sw001.report_search;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    namespace sw001.web_report
    {
    /// <summary>
    /// sw001_report_gcbl 的摘要说明。
    /// </summary>
    public class sw001_report_gcbl : System.Web.UI.Page
    {
    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;

    report_search.report_dll ser=new report_search.report_dll();  ParameterFields param_fileds =new ParameterFields();
    ParameterField  parm_file=new ParameterField();
    ParameterValues param_values=new ParameterValues();
    ParameterDiscreteValue  param_value=new ParameterDiscreteValue();
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if (!IsPostBack)
    {
    if (Request.QueryString["param"].ToString()!="")
    {
    string param_string=Request.QueryString["param"].ToString();
    int flg_param=int.Parse(Request.QueryString["flg"].ToString());
    DataSet ds1=new ds.ds_report_sqwxdj();
    if (flg_param==1)
    { ds1=ser.search_report_gcbl(param_string,flg_param);
    string stryue="";
    if (param_string.Length==6) stryue=param_string.Substring(4,2);
    if (param_string.Length==7) stryue=param_string.Substring(5,2);
    param_value.Value=param_string.Substring(0,4).ToString() + "年" + stryue +"月";
    }
    if (flg_param==2)
    { ds1=ser.search_report_gcbl(param_string,flg_param);
    param_value.Value=param_string + "年";
    }
    if (ds1.Tables["t_sqwxdj"].Rows.Count>0)
    {
    reprot.report_sqwxdj rp_sqwxdj=new reprot.report_sqwxdj();
    rp_sqwxdj.SetDataSource(ds1); param_values.Add(param_value);
    parm_file.ParameterFieldName="param_shijian";
    parm_file.CurrentValues=param_values;
    param_fileds.Add(parm_file);
    this.CrystalReportViewer1.ParameterFieldInfo=param_fileds; this.CrystalReportViewer1.DisplayToolbar=false;
    this.CrystalReportViewer1.DisplayGroupTree=false;
    this.CrystalReportViewer1.ReportSource=rp_sqwxdj;
    }
    else
    {
    Response.Write("<script language=javascript>alert('对不起!没有符合条件的记录,请检查输入的时间是否正确。')</script>");
    Response.Write("<script language=javascript>window.opener=null;window.close();</script>");
    }
    }
    else
    { Response.Write("<script language=javascript>alert('对不起!请输入时间。')</script>"); }
    }
    }
      

  19.   

    数据库的语句一般放在 service1.asmx 中就可以了,每次调用其中的某一个函数的时候,连接数据库。
    欢迎访问 http://pgfans.126.com  编程爱好者俱乐部