【问题标题】:Azure Functions - how to connect to local SQL Server Express database?Azure Functions - 如何连接到本地 SQL Server Express 数据库?
【发布时间】:2018-01-24 01:29:38
【问题描述】:

我正在使用 Azure 函数创建我的第一个应用程序并尝试连接到本地 SQL Server Express 数据库。如何提供连接字符串,以便成功连接到本地 SQL Server Express 数据库?

当我尝试在本地运行应用程序时,出现以下错误:

发生 System.ArgumentException
HResult=0x80070057
消息=不支持关键字:“服务器”。
来源=

堆栈跟踪:

在 System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions.ParseInternal(IDictionary2 parsetable, String connectionString, IList1 validKeywords)
在 System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions..ctor(字符串连接字符串,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() 在 System.Data.Entity.Internal.Linq.InternalSet1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery1.System.Collections.Generic.IEnumerable.GetEnumerator() 在 System.Collections.Generic.List1..ctor(IEnumerable1 集合) 在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 源)

我的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"
            }
        }
    }
}

【问题讨论】:

  • 您使用的 SQL Express 版本是什么?

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


【解决方案1】:

正如错误消息所暗示的那样:Message=Keyword not supported: 'server'。

错误是由于在连接字符串中使用了“server”关键字造成的。

您应该将关键字“服务器”替换为“数据源

Data Source=.\SQLEXPRESS01;Database=myDB;Connection Timeout=30;Integrated Security=SSPI;

或者,您也可以将您的提供商名称修改为 System.Data.SqlClient,而不是更新您现有的连接字符串。

供您参考,这个问题也与之前的问题类似,链接如下:

Keyword not supported: 'server'

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-13
    • 1970-01-01
    • 2013-12-28
    • 1970-01-01
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    相关资源
    最近更新 更多