如何使用ODBC检查数据库是否存在 [英] How to check if a database exists with ODBC

查看:42
本文介绍了如何使用ODBC检查数据库是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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).

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

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

谢谢.

推荐答案

不知道这是否为时已晚,甚至对您来说是否足够便携".

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

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

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

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

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.

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

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!

这篇关于如何使用ODBC检查数据库是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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