Microsoft 企业库连接字符串
大家好,我已成功从代码中显示的数据库实例中获取数据。但是如何从数据库实例中获取数据库名称。我找不到任何与此相关的属性。请帮忙。
private Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("ConnString");
Hi all I've successfully got data out of the database instance shown in the code. But how do I get the database name from the database instance. I can't find any properties regarding this. Please help.
private Database _db = EnterpriseLibraryContainer.Current.GetInstance<Database>("ConnString");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对此没有明确的属性,因为数据库是一个独立于数据库技术的类,并且“数据库名称”的概念是特定于数据库的。哎呀,像 Sqlite 或 SqlCE 这样的东西甚至没有“数据库名称”,只有文件名。
如果您知道数据库的类型,您可以使用“_db.ConnectionString”获取连接字符串,然后对其进行解析。每个 ADO.NET 提供程序都包含一个连接字符串生成器类来为您进行解析。
例如,如果您有 MS Sql 连接字符串,则可以通过以下方式获取数据库名称:
不同的数据库提供商当然会使用不同的属性和术语来为您提供此信息。
There is no explicit property for this, because Database is a database technology independent class, and the concept of "database name" is db specific. Heck, things like Sqlite or SqlCE don't even have "database names", just filenames.
You can use "_db.ConnectionString" to get the connection string back out and then parse through that if you know the type of database. Each ADO.NET provider includes a connection string builder class to do that parsing for you.
For example, if you have a MS Sql connection string, you can get the database name this way:
Different database providers will of course use different properties and terminology to give you this information.