如何使用 ODBC 检查数据库是否存在

发布于 2024-09-13 08:14:30 字数 230 浏览 1 评论 0原文

各位程序员大家好,

我已经在互联网上搜索了几天,但找不到仅使用 ODBC 和 SQL 来解决此问题的通用方法。

有没有办法仅使用ODBC来查看数据库是否已存在。它必须是标准 SQL,因为用户可以选择自己选择的 DSN(即他自己的 SQL Server)。

这意味着我无法检查服务器上的主表,因为它们在不同的 SQL 服务器上的名称不同。

谢谢。

Hello fellow programmers

I have been searching the internet for a few days now and can't find a generic method to solve this with only ODBC and SQL.

Is there a way to see if a database already exist, only using ODBC. It has to be standard SQL because the user can chose a DSN of his choice (meaning his own SQL Server).

This means I can't check the master table on the server because they are named different on different SQL servers.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2024-09-20 08:14:30

不知道这是否为时已晚,或者对您来说是否足够“便携”。

我只需要处理 MS SQL,并且在过去的应用程序中使用 SELECT name FROM master.dbo.sysdatabases WHERE name = @name

但在新的一个中,我使用 ODBC SQLBrowseConnect (传入服务器名称和凭据)来获取服务器中的数据库列表。所以我只是浏览这些。我认为原始代码来自 http://www.codeproject.com/KB/数据库/sqlsrvenumerator.aspx

我不是 ODBC 专家,所以我不知道需要在服务器上运行什么(例如 SQL 浏览器服务),也不知道它的方法/实现方式如何比较。事实上,我不介意是否有其他人评论它是否好/更好!但它似乎是纯粹的 ODBC-only!

Don't know if this is too late, or even sufficiently "portable" for you.

I only have to deal with MS SQL, and in a past application used SELECT name FROM master.dbo.sysdatabases WHERE name = @name.

But in a new one I am using the ODBC SQLBrowseConnect (passing in server name & credentials) to get a list of databases in the server. So I just look through those. I think the original code for that was from http://www.codeproject.com/KB/database/sqlsrvenumerator.aspx.

I'm no ODBC expert, so I don't know what that requires to be running on the server (e.g. SQL Browser service) or how it compares in approach/is implemented. In fact, I wouldn't mind if anyone else comments as to whether it's any good/better! But it seems to be pure ODBC-only!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文