我是C#的初学者,我正在使用网络服务。当我尝试测试我的服务时,会出现以下错误消息:
类型' System.InvalidOperationException'的例外情况发生在System.Data.dll中但未在用户代码中处理
其他信息:实例失败。
这是我在网络配置中的连接字符串:
<connectionStrings>
<add name="connection"
connectionString="Data Source=DESKTOP-CIRUCVV\\SQLEXPRESS;Initial Catalog=CustomerManagerment;Integrated Security=True;"/>
</connectionStrings>
这是我在Web服务类
中的代码using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
namespace WebService
{
/// <summary>
/// Summary description for CustomerService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class CustomerService : System.Web.Services.WebService
{
static string strcon = WebConfigurationManager.ConnectionStrings["connection"].ConnectionString;
public CustomerService() { }
[WebMethod(Description = "Show Customers")]
public DataSet showCustomer()
{
SqlConnection con = new SqlConnection(strcon);
string Sql = "select * from Customers";
SqlDataAdapter da = new SqlDataAdapter(Sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
}
答案 0 :(得分:0)
将DESKTOP-CIRUCVV\\SQLEXPRESS
更改为DESKTOP-CIRUCVV\SQLEXPRESS