如何获取实体模型连接字符串? [英] How to fetch entity model connection string?
本文介绍了如何获取实体模型连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出该实体模型变量:
DataBaseEntities db = new DataBaseEntities ();
下面的代码不能从db varibale连接字符串中使用
The below code can not use from db varibale connection string
SqlBulkCopy sbc = new SqlBulkCopy(db.Connection.ConnectionString);
推荐答案
尝试以下方法:
private string GetADOConnectionString()
{
var db = new DataBaseEntities();
EntityConnection ec = (EntityConnection)db.Connection;
return ec.StoreConnection.ConnectionString;
}
我在这里找到了:从EntityConnection中获取SqlConnection
也请参见此处: EntityConnection.StoreConnection属性
编辑:当然,这应该进行修改,并且您应该检查null或在强制转换之前检查...这只是一个示例;-)
of course this should be adapted and you should check for nulls or check before casting... it's just an example ;-)
这篇关于如何获取实体模型连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文