简体   繁体   English

类型为“ System.Data.SqlClient.SqlException”的异常实例失败

[英]An exception of type 'System.Data.SqlClient.SqlException' Instance failure

I'm a beginner with C# and I'm working with a web service. 我是C#的初学者,并且正在使用Web服务。 When I tried to test my service, this error message occurs: 当我尝试测试我的服务时,会出现以下错误消息:

An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code System.Data.dll中发生类型'System.InvalidOperationException'的异常,但未在用户代码中处理

Additional information: Instance failure. 附加信息:实例故障。

Here is my connection string in web configuration: 这是我在Web配置中的连接字符串:

<connectionStrings>
    <add name="connection" 
         connectionString="Data Source=DESKTOP-CIRUCVV\\SQLEXPRESS;Initial Catalog=CustomerManagerment;Integrated Security=True;"/>
</connectionStrings>

Here is my code inside the web service class 这是我在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;
        }
    }
}

DESKTOP-CIRUCVV\\\\SQLEXPRESS更改为DESKTOP-CIRUCVV\\SQLEXPRESS

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生类型为&#39;System.Data.SqlClient.SqlException&#39;的异常 - An exception of type 'System.Data.SqlClient.SqlException' occurred 类型为&#39;System.Data.SqlClient.SqlException的未处理异常 - An unhandled exception of type 'System.Data.SqlClient.SqlException 设置&#39;引发了&#39;System.Data.SqlClient.SqlException&#39;类型的异常 - Settings' threw an exception of type 'System.Data.SqlClient.SqlException' SqlException was Unhandled An unhandled exception of type &#39;System.Data.SqlClient.SqlException&#39;发生在 System.Data.dll - SqlException was Unhandled An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll System.Data.SqlClient.SqlException - System.Data.SqlClient.SqlException &#39;System.Data.SqlClient.SqlException&#39; - 'System.Data.SqlClient.SqlException' 错误:System.Data.dll 中发生类型为“System.Data.SqlClient.SqlException”的未处理异常 - Error :An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll System.Data.dll中发生类型为&#39;System.Data.SqlClient.SqlException&#39;的异常,但未在用户代码中处理 - A An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code 类型&#39;System.Data.SqlClient.SqlException&#39;的异常发生在&#39;System.Data.dll中,但未在用户代码中处理 - An exception of type 'System.Data.SqlClient.SqlException' occured in 'System.Data.dll but was not handled in user code System.Data.dll 中发生类型为“System.Data.SqlClient.SqlException”的未处理异常; - An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll;
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM