Asp.net无法连接到MSSQL

用户名

当我尝试使用MSSQL在asp.net中启动Web项目时,似乎无法连接到数据库。错误消息是:

A network related or instance specific error occurred while establishing a connection to SQL server...

但是,当我尝试运行以前的项目时,它可以工作。但是,当我选择所有程序-> Microsoft SQL Server 2008->配置工具-> SQL Server配置管理器-> SQL Server服务时。它没有显示所有服务,而是向我显示了一个错误,即远程过程调用失败。

我不知道如何解决此问题,因为它仅发生在我的一个项目中。提前致谢。

SQL Server配置管理器的快照

服务快照

我的web.config代码:

编辑

    <?xml version="1.0" encoding="UTF-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="GeospatialChallenge2014.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpSoap" />
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
    </webServices>
    <compilation debug="true" targetFramework="4.0">
    </compilation>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" />
  </system.web>

  <connectionStrings>
    <add name="GeospatialChallengeConnectionString" connectionString="Data Source=(local);Initial Catalog=SAFETY_AT_SG_DATABASE.mdf;"
    providerName="System.Data.SqlClient" />
  </connectionStrings>

  <applicationSettings>
    <GeospatialChallenge2014.Properties.Settings>
      <setting name="GeospatialChallenge2014"
        serializeAs="String">
        <value>http://localhost/SgDataService.asmx</value>
      </setting>
    </GeospatialChallenge2014.Properties.Settings>
  </applicationSettings>
  <system.webServer>
    <directoryBrowse enabled="true" />
  </system.webServer>
</configuration>

和我的连接字符串:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

using System.Xml;

namespace Geospatial_Challenge_2014
{
    /// <summary>
    /// Summary description for SgDataService
    /// </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 SgDataService : System.Web.Services.WebService
    {

        [WebMethod]
        public DataSet GetTrafficByDateTime(string StartDateTime, string EndDateTime)
        {
            //System.Data.SqlClient.SqlConnection myConn = new System.Data.SqlClient.SqlConnection();
            //myConn.ConnectionString = @"Data Source=(local);Initial Catalog=SAFETY_AT_SG_DATABASE.MDF;Integrated Security=True";
            SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["GeospatialChallengeConnectionString"].ConnectionString);
            SqlDataAdapter myAdapter = new SqlDataAdapter("Select * from dbo.Traffic where Convert(DateTime,([date]+' '+[time])) >= @StartDateTime AND Convert(DateTime,([date]+' '+[time])) <= @EndDateTime;", myConn);
            myAdapter.SelectCommand.Parameters.AddWithValue("@StartDateTime", StartDateTime);
            myAdapter.SelectCommand.Parameters.AddWithValue("@EndDateTime", EndDateTime);
            DataSet ds = new DataSet();
            myConn.Open();
            myAdapter.Fill(ds, "Traffic");
            myConn.Close();
            return ds;
        }
    }
}
威尔逊

杜德(Dude)在web.config本身内定义连接字符串,然后尝试。

<connectionStrings>
<add name="DBConnection" connectionString="Data Source=yourservername;Initial    
Catalog=DBname;User ID=sa;Password=yourpassword" 
providerName="System.Data.SqlClient" />
</connectionStrings>

并在您的方法中调用连接字符串为

SqlConnection objConnection = new SqlConnection();//sql connection object
objConnection.ConnectionString = ConfigurationManager.ConnectionStrings
["DBConnection"].ConnectionString; //conn string name as in config file
SqlCommand cmd = new SqlCommand("YourStoredprocedure", objConnection);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用ASP.NET连接到MSSQL Express

来自分类Dev

Blazor无法连接到ASP.NET Core WebApi(CROS)

来自分类Dev

ASP.NET MVC 错误 50 无法连接到 localDB

来自分类Dev

无法从 javascript 连接到 ASP.NET Core websocket

来自分类Dev

连接到设备ASP.NET MVC

来自分类Dev

MS Access 连接到 ASP.NET

来自分类Dev

Dockerized Asp.net Core无法连接到WSL中的主机的Kafka

来自分类Dev

无法从Docker中的ASP.NET Core 3.1连接到内部SQL Server

来自分类Dev

通过Visual Studio在本地运行时无法连接到ASP.NET站点

来自分类Dev

无法将asp.net页面连接到MySQL数据库

来自分类Dev

部署到托管站点后,ASP.net无法连接到SQL Server

来自分类Dev

ASP.NET MVC 错误消息“无法连接到 Visual Studio 开发服务器”。

来自分类Dev

无法连接到我的 ASP.NET MVC 项目中的 Neo4j db

来自分类Dev

无法从ASP.NET连接到AX Web服务,但可以从控制台应用程序连接

来自分类Dev

无法连接到MSSQL Server

来自分类Dev

Netbeans无法连接到MSSQL

来自分类Dev

Freetds无法连接到MSSQL

来自分类Dev

ASP.NET Core Web API服务无法连接到同一网络上的Docker SQL Server

来自分类Dev

连接到SQL Server的自定义ASP.Net预订日历(希望使某些天无法进行预订)

来自分类Dev

连接到ASP.NET C#查询中的表〜多部分标识符无法绑定

来自分类Dev

ASP.NET MVC 4 EF6无法连接到SQL Server Express数据库

来自分类Dev

将Azure AD连接到ASP.NET MVC站点

来自分类Dev

将Firebird连接到ASP.net WebAPI项目

来自分类Dev

从IIS(ASP.Net Core)连接到SQL Server

来自分类Dev

将ASP.NET连接到Amazon RDS MariaDB

来自分类Dev

无法使用Schemacrawler连接到MSSQL

来自分类Dev

由于基于角色的[Authorize]属性,ASP.NET MVC 5 Azure网站无法在某些视图上连接到SQL Azure DB

来自分类Dev

无法将具有EFCore Mysql提供程序的Docker中的Asp.net Core WebApi连接到主机服务器上的非Docker Mysql

来自分类Dev

OS X 10.10.4无法连接到LAN上的IIS Express asp.net Web服务器(但其他Windows机器可以)

Related 相关文章

  1. 1

    如何使用ASP.NET连接到MSSQL Express

  2. 2

    Blazor无法连接到ASP.NET Core WebApi(CROS)

  3. 3

    ASP.NET MVC 错误 50 无法连接到 localDB

  4. 4

    无法从 javascript 连接到 ASP.NET Core websocket

  5. 5

    连接到设备ASP.NET MVC

  6. 6

    MS Access 连接到 ASP.NET

  7. 7

    Dockerized Asp.net Core无法连接到WSL中的主机的Kafka

  8. 8

    无法从Docker中的ASP.NET Core 3.1连接到内部SQL Server

  9. 9

    通过Visual Studio在本地运行时无法连接到ASP.NET站点

  10. 10

    无法将asp.net页面连接到MySQL数据库

  11. 11

    部署到托管站点后,ASP.net无法连接到SQL Server

  12. 12

    ASP.NET MVC 错误消息“无法连接到 Visual Studio 开发服务器”。

  13. 13

    无法连接到我的 ASP.NET MVC 项目中的 Neo4j db

  14. 14

    无法从ASP.NET连接到AX Web服务,但可以从控制台应用程序连接

  15. 15

    无法连接到MSSQL Server

  16. 16

    Netbeans无法连接到MSSQL

  17. 17

    Freetds无法连接到MSSQL

  18. 18

    ASP.NET Core Web API服务无法连接到同一网络上的Docker SQL Server

  19. 19

    连接到SQL Server的自定义ASP.Net预订日历(希望使某些天无法进行预订)

  20. 20

    连接到ASP.NET C#查询中的表〜多部分标识符无法绑定

  21. 21

    ASP.NET MVC 4 EF6无法连接到SQL Server Express数据库

  22. 22

    将Azure AD连接到ASP.NET MVC站点

  23. 23

    将Firebird连接到ASP.net WebAPI项目

  24. 24

    从IIS(ASP.Net Core)连接到SQL Server

  25. 25

    将ASP.NET连接到Amazon RDS MariaDB

  26. 26

    无法使用Schemacrawler连接到MSSQL

  27. 27

    由于基于角色的[Authorize]属性,ASP.NET MVC 5 Azure网站无法在某些视图上连接到SQL Azure DB

  28. 28

    无法将具有EFCore Mysql提供程序的Docker中的Asp.net Core WebApi连接到主机服务器上的非Docker Mysql

  29. 29

    OS X 10.10.4无法连接到LAN上的IIS Express asp.net Web服务器(但其他Windows机器可以)

热门标签

归档