我在一个运行良好的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
我使用Azure Kudu进行了检查,文件位于正确的路径中…
但是,当我运行应用程序时,我不断收到错误.
有谁知道如何解决这个问题?
UPDATE
我的实体框架类如下:
[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>