| 1 | <HTML> |
| 2 | <HEAD> |
| 3 | <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1"> |
| 4 | <TITLE>Obtainign Datasources</TITLE> |
| 5 | <LINK REL="Stylesheet" href="odbc.css"> |
| 6 | </HEAD> |
| 7 | <BODY bgcolor="white"> |
| 8 | |
| 9 | <table width="90%" cols="3" border="0"> |
| 10 | <TR> |
| 11 | <TD colspan="3" class="big">Obtaining a Datasourcename</TD> |
| 12 | </TR> |
| 13 | <TR> |
| 14 | <TD colspan="3"><P>A simple query should be a nobrainer right now. But what if |
| 15 | your program runs on a system where you can't be sure which datasource names |
| 16 | are configured?</P> |
| 17 | <P>Then you should use <A hrEF="gloss.html#dsn"><CODE>SQLDataSources()</CODE></a>. |
| 18 | After allocating a environment handle you may use this to find out about the |
| 19 | DSN and the supplied description for the datasource.</P> |
| 20 | <P>As ODBC knows systemwide and userwide datasources, you need to give a direction |
| 21 | which datasource types you are looking for. There you may specify either of the |
| 22 | following values:</P> |
| 23 | <TABLE COLS="2" border="0" width="90%"> |
| 24 | <TR> |
| 25 | <TD valign="top"><CODE>SQL_FETCH_FIRST</CODE></TD> |
| 26 | <TD>Sets up <CODE>SQLDataSources()</CODE> to lookup the first of all |
| 27 | available datasources (either user or systemwide). |
| 28 | </TR> |
| 29 | <TR> |
| 30 | <TD valign="top"><CODE>SQL_FETCH_FIRST_USER</CODE></TD> |
| 31 | <TD>Sets up <CODE>SQLDataSources()</CODE> to lookup the first of the |
| 32 | available user datasources. |
| 33 | </TR> |
| 34 | <TR> |
| 35 | <TD valign="top"><CODE>SQL_FETCH_FIRST_SYSTEM</CODE></TD> |
| 36 | <TD>Sets up <CODE>SQLDataSources()</CODE> to lookup the first of the |
| 37 | available system datasources. |
| 38 | </TR> |
| 39 | <TR> |
| 40 | <TD valign="top"><CODE>SQL_FETCH_NEXT</CODE></TD> |
| 41 | <TD>Fetches the next datasource. |
| 42 | Depending on <CODE>SQL_FETCH_FIRST_USER</CODE>, <CODE>SQL_FETCH_FIRST_SYSTEM</CODE> |
| 43 | or <CODE>SQL_FETCH_FIRST</CODE> this may only be a user datasource, |
| 44 | only a system datasource or one of either. |
| 45 | </TR> |
| 46 | </TABLE> |
| 47 | <P>So let's have a look on a small function, which will return all available |
| 48 | datasource names. You may insert this code into the program which you built before and call it somewhere after you've obtained an environment handle.</P> |
| 49 | <CODE class="list"><PRE> |
| 50 | void OD_ListDSN(void) |
| 51 | { |
| 52 | char l_dsn[100],l_desc[100]; |
| 53 | short int l_len1,l_len2,l_next; |
| 54 | |
| 55 | l_next=SQL_FETCH_FIRST; |
| 56 | while( SQLDataSources(V_OD_Env,l_next,l_dsn, sizeof(l_dsn), |
| 57 | &l_len1, l_desc, sizeof(l_desc), &l_len2) == SQL_SUCCESS) |
| 58 | { |
| 59 | printf("Server=(%s) Beschreibung=(%s)\n",l_dsn,l_desc); |
| 60 | l_next=SQL_FETCH_NEXT; |
| 61 | } |
| 62 | } |
| 63 | </PRE></CODE> |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | </TD> |
| 69 | </TR> |
| 70 | </TABLE> |
| 71 | </BODY> |
| 72 | </HTML> |