BCB中,怎样将ODBC数据源名称传入ComboBox的列表中?

saucerman 2000-03-03 07:00:00
C++ Builder中,怎样将已建立的ODBC DSN传入ComboBox的列表中以供选择?
...全文
244 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucerman 2000-03-04
  • 打赏
  • 举报
回复
谢谢!尽管我已经按Registry的方法将它解决。
但多知道一种解法,多学一点东东总没坏处。
可惜我只有50分了,请在您源码相助我看可行后——
我重再挂个贴,请您去取50分吧。
不论助人助已,热心相助的人理应有奖赏啊!
My E_mail: truejun@21cn.com
Wingsun 2000-03-04
  • 打赏
  • 举报
回复
你要使用的是SQLDataSources,而不是SQLBrowseConnect.我有源程序。可联系。
saucerman 2000-03-03
  • 打赏
  • 举报
回复
guo大侠是对的,DSN确实是存在Registry里,他所清晰地告诉我们的地方。
他的方法应该绝对可行,其他方法可能也要在注册表里读数据。
guo大侠!
也谢谢Lin及Wingsun!
Lin 2000-03-03
  • 打赏
  • 举报
回复
我没试过,但在Delphi可以只要你添加TSession控件即可:
Session.GetDatabaseNames可获得所有BDE数据库别名,其中包括ODBC,定义如下:
procedure TSession.GetDatabaseNames(List: TStrings);
saucerman 2000-03-03
  • 打赏
  • 举报
回复
Wingsun大侠:

只找到以下说明,怎么用还是一头雾水——

SQLBrowseConnect (ODBC)
SQLBrowseConnect uses keywords that can be categorized into three levels of connection information. For each keyword, the following table indicates whether a list of valid values is returned and whether the keyword is optional.

Level 1

Keyword List returned? Optional? Description
DSN N/A No Name of the data source as it is returned by SQLDataSources. The DSN keyword cannot be used if the DRIVER keyword is used.
DRIVER N/A No SQL Server ODBC driver name is {SQL Server} or SQL Server (the braces are required when using the 2.65 or earlier versions of the driver). The DRIVER keyword cannot be used if the DSN keyword is used.


Level 2

Keyword List returned? Optional? Description
SERVER Yes No Name of the server on the network on which the data source resides. When running on Microsoft® Windows NT®, “(local)” can be entered as the server, in which case a local copy of Microsoft SQL Server™ can be used, even when this is a nonnetworked version.
UID No Yes User login ID.
PWD No Yes (depends on the user) User-specified password.
APP No Yes Name of the application calling SQLBrowseConnect.
WSID No Yes Workstation ID. Typically, this is the network name of the computer on which the application runs.


Level 3

Keyword List returned? Optional? Description
DATABASE Yes Yes Name of the SQL Server database.
LANGUAGE Yes Yes National language to be used by SQL Server.


SQLBrowseConnect ignores the values of the DATABASE and LANGUAGE keywords that are stored in the ODBC data source definitions. If the database or language specified in the connection string passed to SQLBrowseConnect is invalid, SQLBrowseConnect returns SQL_NEED_DATA and the level 3 connection attributes.

SQLBrowseConnect doesn’t check user access to all the databases listed with the DATABASE keyword when connected to SQL Server version 6.5 or earlier servers. If the user doesn’t have access to the chosen database, SQLBrowseConnect returns SQL_NEED_DATA and the level 3 connection attributes.



(c) 1988-98 Microsoft Corporation. All Rights Reserved
Wingsun 2000-03-03
  • 打赏
  • 举报
回复
使用SQLDataSources,通过返回的参数可以判断DSN的类型,详情可见MSDN的HELP
guo 2000-03-03
  • 打赏
  • 举报
回复
我曾经在Delphi中做过列出ODBC数据源的combobox组件,详细过程在这里说不清楚,最主要的是从HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources下有所有用户ODBC数据源的键名.在HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC Data Sources下的是所有系统ODBC数据源的键名.在HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC File DSN下的是所有文件DSN,通过它们的值可以区分数据源的类型,过滤特定的数据源.
简单地说就是直接读取注册表信息并进行过滤即可.
我说的是否清楚?

saucerman 2000-03-03
  • 打赏
  • 举报
回复
补充:传入的ODBC DSN列表最好能是被过滤了的。
比如,只是SQL Server的DSN,或都是DB2的DSN。

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧