我正在使用 Azure 函数创建我的第一个应用程序,并尝试连接到本地 SQL Server Express 数据库。如何提供连接字符串以便能够成功连接到本地 SQL Server Express 数据库?
当我尝试在本地运行应用程序时,出现以下错误:
System.ArgumentException occurred
HResult=0x80070057
Message=Keyword not supported: 'server'.
Source=StackTrace:
at System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions.ParseInternal(IDictionary
2 parsetable, String connectionString, IList
1 validKeywords)
at System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions..ctor(String connectionString, IList1 validKeywords) at System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString) at System.Data.Entity.Core.EntityClient.EntityConnection..ctor(String connectionString) at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection) at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config) at System.Data.Entity.Internal.LazyInternalConnection.Initialize() at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName() at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName() at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context) at System.Data.Entity.Internal.LazyInternalContext.InitializeContext() at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) at System.Data.Entity.Internal.Linq.InternalSet
1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery
1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable
1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
我的 local.settings.json
看起来像这样:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "xxx",
"AzureWebJobsDashboard": "xxx"
},
"ConnectionStrings": {
"RecConnectionString": {
"ConnectionString": "Server=localhost\\SQLEXPRESS01;Database=myDB;Connection Timeout=30;Integrated Security=SSPI;",
"ProviderName": "System.Data.EntityClient"
}
},
"frameworks": {
"net46": {
"dependencies": {
"EntityFramework": "6.0.0",
"Newtonsoft.Json": "10.0.3"
}
}
}
}
最佳答案
如错误消息所示:Message=不支持关键字:“服务器”。
该错误是由于在连接字符串中使用“server”关键字引起的。
您应该将关键字“服务器”替换为“数据源”
Data Source=.\SQLEXPRESS01;Database=myDB;Connection Timeout=30;Integrated Security=SSPI;
或者,您也可以将提供程序名称修改为 System.Data.SqlClient
,而不是更新现有的连接字符串。
供您引用,此问题也与以下链接中的上一个问题类似:
Keyword not supported: 'server'
希望这有帮助。
关于sql-server - Azure Functions - 如何连接到本地 SQL Server Express 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48413511/