我在一个运行良好的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>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。