ServerVersion”引发了类型为“ System.InvalidOperationException”的异常

时间:2019-12-04 10:58:17

标签: sql-server connection-string

在与using块连接之前,我正在使用连接字符串设置DbContextOptions

//configutaion of dbContextOptions with the selected connection string
var optionsBuilder = new DbContextOptionsBuilder<AZPDBDEMOGZContext>();
optionsBuilder.UseSqlServer(EConnectionString);

using (var context = new AZPDBDEMOGZContext(optionsBuilder.Options))
{                
    var name= context.Database.GetDbConnection();   
    ...
}

变量名称用于测试,到达变量名时会出现此异常:

  

ServerVersion ='(((System.Data.SqlClient.SqlConnection)name).ServerVersion'引发了类型为'System.InvalidOperationException'的异常

那意味着连接没有成功?该如何解决?

0 个答案:

没有答案