Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

SQL Server connection string in Appsettings.json + .net Core 3.1

I'm trying to setup and connect to my remote development SQL Server (SQL 2017) in appsettings.json within .NET Core 3.1, I have tried the following approaches yet without any success.

 "ConnectionStrings": {
//"DefaultConnection1": "DATA SOURCE=[servername];UID=[username];PWD=[password];DATABASE=[databasename]",
//"DefaultConnection2": "Data Source=[servername]; Initial Catalog=[databasename];User ID=[username];Password=[password]",
//"DefaultConnection3": "DataSource=[servername];Initial Catalog=[databasename];User Id=[username];password=[password]",
"DefaultConnection4": "Server=[servername];Database=[databasename];User Id=[username];password=[password];Trusted_Connection=False;MultipleActiveResultSets=true;" 
},

Error of DefaultConnection1:

ArgumentException: Keyword not supported: 'uid'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string keyword))

Error of DefaultConnection2:

ArgumentException: Keyword not supported: 'initial catalog'. Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string keyword)

Error of DefaultConnection3:

ArgumentException: Keyword not supported: 'initial catalog'. Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string keyword)

Error of DefaultConnection4:

ArgumentException: Keyword not supported: 'server'.
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(string keyword)

Any ideas, pointers or help is much appreciated.

question from:https://stackoverflow.com/questions/65843095/sql-server-connection-string-in-appsettings-json-net-core-3-1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Probably it's just because you're not supposed to put comments (//) in JSON as JSON is a data format and doesn't support comments. So try actually removing the lines starting with // from your config.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...