gpt4 book ai didi

Azure 上的 SQLite : The server was not found or was not accessible

转载 作者:行者123 更新时间:2023-12-03 02:21:01 24 4
gpt4 key购买 nike

我在 Asp.Net MVC 5 项目中使用 SQLite,该项目运行良好。

我将应用程序上传到 Microsoft Azure,但收到以下错误:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 
The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

在 Azure 中,我添加了以下连接字符串:

Data Source=D:\home\site\wwwroot\Data\MyDatabase.sqlite;Password=pass

由于没有 SqlLite 数据库选项,我选择了自定义: enter image description here

我使用 Azure Kudu 检查过,文件位于正确的路径中...

但是,当我运行该应用程序时,我不断收到错误。

有人知道如何解决这个问题吗?

更新

我的 Entity Framework 类如下:

[DbConfigurationType(typeof(Configuration))]
public class Context : DbContext, IDbContext {

public Context() {
Configuration.With(x => {
x.AutoDetectChangesEnabled = true;
x.LazyLoadingEnabled = false;
x.ProxyCreationEnabled = true;
x.ValidateOnSaveEnabled = true;
});
}

public DbSet<Post> Posts { get; set; }
public DbSet<Tag> Tags { get; set; }

protected override void OnModelCreating(DbModelBuilder builder) {
}

}

public class Configuration : DbConfiguration {
public Configuration() {
SetDatabaseInitializer<Context>(null);
SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
}
}

我在 Global.asax 上有以下内容:

AppDomain.CurrentDomain.SetData("DataDirectory", AppDomain.CurrentDomain.BaseDirectory + "Data");

builder.RegisterType<Context>().As<IDbContext>().InstancePerRequest();

Web.Config 中的连接字符串是:

<connectionStrings>
<add name="Context" providerName="System.Data.SQLite" connectionString="Data Source=|DataDirectory|\MyDatabase.sqlite;Version=3;Password=pass" />
</connectionStrings>

最佳答案

我找到了解决方案。我需要在 Azure 中为 DataDirectory 定义一个应用程序设置,而不是在 Azure 中定义 ConnectionString,其中值是 Azure 中数据库所在的目录...

可以使用 Kudu 的调试控制台找到 Azure 中数据库位置的绝对路径。

按照我的示例,DataDirectory 应用程序设置将具有:

Key: DataDirectory
Value: D:\home\site\wwwroot\Data

关于Azure 上的 SQLite : The server was not found or was not accessible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44181013/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com