Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.ArgumentException:初始化字符串的格式不符合从索引0开始的规范。3._C#_Asp.net Web Api_.net Core - Fatal编程技术网

C# System.ArgumentException:初始化字符串的格式不符合从索引0开始的规范。3.

C# System.ArgumentException:初始化字符串的格式不符合从索引0开始的规范。3.,c#,asp.net-web-api,.net-core,C#,Asp.net Web Api,.net Core,我正在尝试制作一个.NET核心Web API,但我找不到解决问题的方法 完全错误是 [ERR]对上下文类型“MailAlertWebApiWithEF.Data.AlertContext”的查询结果进行迭代时,数据库中发生异常 “”System.ArgumentException:初始化字符串的格式不符合从索引0开始的规范 我从一个现有的数据库中获取配置代码 Scaffold DbContext“server=。;ConnectionString“Microsoft.EntityFramewor

我正在尝试制作一个.NET核心Web API,但我找不到解决问题的方法

完全错误是

[ERR]对上下文类型“MailAlertWebApiWithEF.Data.AlertContext”的查询结果进行迭代时,数据库中发生异常 “”System.ArgumentException:初始化字符串的格式不符合从索引0开始的规范

我从一个现有的数据库中获取配置代码

Scaffold DbContext“server=。;ConnectionString“Microsoft.EntityFrameworkCore.SqlServer-OutputDir DBModels-force-v

我的配置是:

 public class AlertModelConfiguration<T>:BaseEntityModelConfiguration<T,int> where T:Alert
{

    public AlertModelConfiguration(ref ModelBuilder modelBuilder):base(ref modelBuilder)
    {
        modelBuilder.Entity<Alert>(entity =>
        {
            //entity.HasKey(e => e.AlertId);

            entity.Property(e => e.CreateDate).HasColumnType("datetime");

            entity.Property(e => e.DeleteDate).HasColumnType("datetime");

            entity.Property(e => e.Detail)
                .IsRequired()
                .HasMaxLength(2046)
                .IsUnicode(false);

            entity.Property(e => e.ErrorDetail)
                .IsRequired()
                .HasMaxLength(255)
                .IsUnicode(false);

            entity.Property(e => e.Title)
                .HasMaxLength(50)
                .IsUnicode(false);

            entity.Property(e => e.UpdateDate).HasColumnType("datetime");
        });
     }
}
当我在调试模式下启动时,API会卡在引擎层中

我的发动机和发动机:

Task<CustomListEntity<Alert>> GetByIdAsync(int id);

 public  Task<CustomListEntity<Alert>> GetByIdAsync(int id)
    {
        return  CommonOperationAsync(async () =>
         {
             var predicate = PredicateBuilder.True<Alert>();
             predicate = predicate.And(p => p.Id == id);

             

             return new CustomListEntity<Alert>()
             {
                 EntityList = await _alertReqository.GetAll(skip: 0, take: 10, predicate: predicate,
                     orderExpression: null, rowCount: out var count, ascending: false).ToListAsync(),

                 Count = count,
             };
         }, new BusinessBaseRequest()
         {
             MethodBase = MethodBase.GetCurrentMethod()
         }, BusinessUtilMethod.CheckRecordIsExist, GetType().Name);
    }
任务GetByIdAsync(int-id);
公共任务GetByIdAsync(int id)
{
返回CommonOperationAsync(异步()=>
{
var predicate=PredicateBuilder.True();
谓词=谓词和(p=>p.Id==Id);
返回新的CustomListenty()
{
EntityList=await _AlertRePository.GetAll(跳过:0,执行:10,谓词:谓词,
orderExpression:null,rowCount:out var count,升序:false)。ToListSync(),
计数=计数,
};
},新的BusinessBaseRequest()
{
MethodBase=MethodBase.GetCurrentMethod()
},BusinessUtilMethod.CheckRecordIsExist,GetType().Name);
}

我尝试了自己的配置文件,但结果相同。有什么问题吗?

此错误表明您的连接字符串不正确

单词“pooling”中有输入错误,请尝试使用以下连接字符串:

ConnectionStrings": {
         "AlertContext": "server=.;database=*****;pooling=false; 
                 Timeout=60;Integrated Security=SSPI"

如果仍不工作,请确保服务器和数据库值正常。

此错误表示连接字符串不正确

单词“pooling”中有输入错误,请尝试使用以下连接字符串:

ConnectionStrings": {
         "AlertContext": "server=.;database=*****;pooling=false; 
                 Timeout=60;Integrated Security=SSPI"

如果仍然不工作,请确保服务器和数据库值正常。

我也遇到了同样的错误,但问题不在于连接字符串,而是由于以下一些混淆:

在Startup.cs文件中,我添加了以下错误设置:

services.AddDbContext<EFCFWithExistingDBContext>(x => x.UseSqlServer(MyDatabaseConnection));
services.AddDbContext(x=>x.UseSqlServer(MyDatabaseConnection));
下面是正确的代码。我的错误已经消失了

services.AddDbContext<EFCFWithExistingDBContext>(x => x.UseSqlServer(Configuration.GetConnectionString("MyDatabaseConnection")));
services.AddDbContext(x=>x.UseSqlServer(Configuration.GetConnectionString(“MyDatabaseConnection”));

我也遇到了同样的错误,但问题不在于连接字符串,而是由于以下一些混淆:

在Startup.cs文件中,我添加了以下错误设置:

services.AddDbContext<EFCFWithExistingDBContext>(x => x.UseSqlServer(MyDatabaseConnection));
services.AddDbContext(x=>x.UseSqlServer(MyDatabaseConnection));
下面是正确的代码。我的错误已经消失了

services.AddDbContext<EFCFWithExistingDBContext>(x => x.UseSqlServer(Configuration.GetConnectionString("MyDatabaseConnection")));
services.AddDbContext(x=>x.UseSqlServer(Configuration.GetConnectionString(“MyDatabaseConnection”));