簡體   English   中英

Azure功能-如何連接到本地SQL Server Express數據庫?

[英]Azure Functions - how to connect to local SQL Server Express database?

我正在創建具有Azure功能的第一個應用程序,並嘗試連接到本地SQL Server Express數據庫。 如何提供連接字符串,以便我可以成功連接到本地SQL Server Express數據庫?

當我嘗試在本地運行應用程序時,這是我得到的錯誤:

發生System.ArgumentException
的HResult = 80070057
Message =不支持的關鍵字:“服務器”。
來源=

堆棧跟蹤:

在System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions.ParseInternal(IDictionary 2 parsetable, String connectionString, IList 1 validKeywords)
在System.Data.Entity.Core.EntityClient.EntityConnection.ChangeConnectionString(String 1 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在System.Data.Entity.Core.EntityClient.Internal.DbConnectionOptions..ctor(String connectionString,IList 1 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 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.System.Data.Entity.Internal.Linq.InternalSet 1.Initialize()中的1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery 1中的1.GetEnumerator() at System.Data.Entity.Infrastructure.DbQuery System.Linq.Enumerable.ToList [TSource]的System.Collections.Generic.List的1..ctor(IEnumerable )(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"
            }
        }
    }
}

如錯誤消息所暗示: Message = Key不支持的關鍵字:“服務器”。

該錯誤是由於在連接字符串中使用'server'關鍵字引起的。

您應將關鍵字“服務器”替換為“ 數據源

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

或者,您也可以將提供程序名稱修改為System.Data.SqlClient而不是更新現有的連接字符串。

供您參考,此問題也與以下鏈接中的上一個問題類似:

不支持的關鍵字:“服務器”

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM