sql-server - Azure Functions - 如何连接到本地 SQL Server Express 数据库?

标签 sql-server entity-framework azure database-connection azure-functions

我正在使用 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(IDictionary2 parsetable, String connectionString, IList1 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.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 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/

相关文章:

C# 按实体类型自动创建存储库

c# - 如何以 RESTful 方式表示/维护主要细节关系?

azure - 将 SQL Server 数据库从 Azure 迁移到 AWS

azure - 将 NuGet 包从 yaml 管道发布到组织源

azure - Terraform Azure - 将现有的 Azure SQL 数据库移至弹性池中

sql - 向 Azure 数据工厂中的表添加新列

sql-server - SQL Server 输出子句转换为标量变量

sql-server - 为什么在 SQL Server 批量插入期间格式化文件会导致错误?

sql - 如何将存储过程编写到文件中?

c# - 使用 LINQ 计算嵌套的导航表行