Dapper连接问题:TCP提供程序,错误:40-无法打开与SQL Server的连接

问题描述 投票:-3回答:1

我正在尝试使用Dapper在Microsoft SQL Server中执行查询。我正在使用的代码如下:

public void Insert_Cycle(int cylinderId, int cycleNumber, float cycleMaxPressure, float cyleMinPressure, DateTime cycleStartTime, DateTime cyleEndTime)
        {
            using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["DB Name"].ConnectionString))
            {

            Models.T6Testing newcycle = new Models.T6Testing { CylinderId = cylinderId, CycleNumber = cycleNumber, CycleMaxPressure = cycleMaxPressure, CyleMinPressure = cyleMinPressure, CycleStartTime = cycleStartTime, CyleEndTime = cyleEndTime };
            List<Models.T6Testing> cycles = new List<Models.T6Testing>();
            cycles.Add(new Models.T6Testing { CylinderId = cylinderId, CycleNumber = cycleNumber, CycleMaxPressure = cycleMaxPressure, CyleMinPressure = cyleMinPressure, CycleStartTime = cycleStartTime, CyleEndTime = cyleEndTime });
            db.Execute("dbo.SP_INSERT_CYCLE @Cylinder_ID,@Cycle_number,@Cycle_max_pressure,@Cycle_min_pressure,@Cycle_start_time,@Cycle_end_time", cycles);
            }
        }

连接字符串采用以下格式:

<add name="DB Name"
      connectionString="Data Source=x.x.x.x,#port;Initial Catalog=Database Name;Persist Security Info=True;User ID=sa;Password=xxxxxx"
      providerName="System.Data.SqlClient" />
  </connectionStrings>  

为了测试连接字符串的格式是否正确,我使用了https://www.vadimtabakman.com/connection-string-tester.aspx中的vttestconnectionstring,并且能够使用它运行查询。有人可以指出我犯错的正确方向吗?

c# sql-server windows dapper
1个回答
0
投票

语法和连接字符串正确。问题出在UWP项目中,在Package.appxmanifest中未将Internet添加到功能中。

© www.soinside.com 2019 - 2024. All rights reserved.