You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Singlar.NET的appsettings.json中配置SQL Server连接字符串?

配置appsettings.json中的数据库连接字符串

SQL Server 连接字符串示例

把配置里的"Your connection string"替换成对应格式的实际字符串即可:

  • Windows 认证(本地实例):
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "SqlServer": "Server=(localdb)\\mssqllocaldb;Database=你的数据库名;Trusted_Connection=True;MultipleActiveResultSets=true"
  }
}
  • SQL Server 账号密码认证:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "SqlServer": "Server=你的服务器地址;Database=你的数据库名;User Id=你的账号;Password=你的密码;MultipleActiveResultSets=true"
  }
}

其他常用数据库配置示例

如果用 MySQL:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "MySql": "Server=localhost;Database=你的数据库名;Uid=你的账号;Pwd=你的密码;"
  }
}

如果用 SQLite:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings": {
    "Sqlite": "Data Source=你的数据库文件名.db"
  }
}

注意事项

  • 所有占位符(比如你的数据库名、你的服务器地址)要替换成你实际的数据库信息
  • MultipleActiveResultSets=true用于允许同一连接同时处理多个结果集,可根据需求决定是否保留
  • Windows 认证模式下无需输入账号密码,依赖当前运行程序的系统权限

内容的提问来源于stack exchange,提问作者soban khan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 12:26:00