[InvalidOperationException:此操作需要连接到'master'数据库。 [英] [InvalidOperationException: This operation requires a connection to the 'master' database.

查看:78
本文介绍了[InvalidOperationException:此操作需要连接到'master'数据库。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我第一次尝试使用目录时收到错误


 
using var db = new ProfileCatalog())
{
bool userExists = db.Profiles.Where(x => x.Username == username).Any();

//在这里抛出异常

解决方案

ColinM123,


 


默认情况下,我们检查是否第一次在AppDomain中使用上下文时,您尝试使用的数据库就存在。 
此检查需要连接到主数据库,使用您正在使用的连接时无法连接。 
我们会考虑改善这种体验。 
现在,尝试在应用程序初始化的某个时刻添加以下调用(在第一次使用DbContext之前):


 


   
数据库
.SetInitializer< ProfileCatalog >( null );


 


这将告诉Magic Unicorn不要尝试任何初始化,包括跳过检查数据库是否存在。


 


谢谢,


Arthur


Hi,

I am getting an error the first time I try and use my catalog

      using (var db = new ProfileCatalog())
      {
        bool userExists = db.Profiles.Where(x => x.Username == username).Any();

// throws exception here

解决方案

ColinM123,

 

By default, we check if the database you are trying to use exists the first time that the context is used in an AppDomain.  This check requires a connection to the master database, which it appears is not possible with the connection you are using.  We will look into making this experience better.  For now, try adding the following call at some point in your application initialization (before you use the DbContext for the first time):

 

    Database.SetInitializer<ProfileCatalog>(null);

 

This will tell Magic Unicorn to not attempt any initialization, including skipping the check for whether or not the database exists.

 

Thanks,

Arthur


这篇关于[InvalidOperationException:此操作需要连接到'master'数据库。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆