|
| 1 | +--- |
| 2 | +title: "SQLCreateDataSourceExW Function" |
| 3 | +description: "SQLCreateDataSourceExW Function" |
| 4 | +author: corylaban |
| 5 | +ms.author: corylaban |
| 6 | +ms.date: "05/07/2025" |
| 7 | +ms.service: sql |
| 8 | +ms.subservice: connectivity |
| 9 | +ms.topic: reference |
| 10 | +f1_keywords: |
| 11 | + - "SQLCreateDataSourceExW" |
| 12 | +helpviewer_keywords: |
| 13 | + - "SQLCreateDataSourceExW function [ODBC]" |
| 14 | +apilocation: "odbccp32.dll" |
| 15 | +apiname: "SQLCreateDataSourceExW" |
| 16 | +apitype: "dllExport" |
| 17 | +--- |
| 18 | +# SQLCreateDataSourceExW Function |
| 19 | +**Conformance** |
| 20 | + Version Introduced: ODBC 2.0 |
| 21 | + |
| 22 | + **Summary** |
| 23 | + **SQLCreateDataSourceExW** adds a data source programmatically. |
| 24 | + |
| 25 | +> [!WARNING] |
| 26 | +> The `SQLCreateDataSourceExW` function is private and isn't meant to be used directly in your code. |
| 27 | +> Microsoft doesn't support the use of this field in a production application under any circumstance. |
| 28 | +
|
| 29 | +## Syntax |
| 30 | + |
| 31 | +```cpp |
| 32 | +typedef enum tagDSNType |
| 33 | +{ |
| 34 | + evCreateAnyDSN, |
| 35 | + evCreateMachineDSN, |
| 36 | + evCreateUserDSN, |
| 37 | + evCreateSystemDSN, |
| 38 | + evCreateFileDSN |
| 39 | +} DSN_TYPE; |
| 40 | + |
| 41 | +#define DSNC_ATTEMPT_CONN 0x00000001 |
| 42 | +#define DSNC_DRIVER_ONLY 0x00000002 |
| 43 | + |
| 44 | +typedef struct tagODBCDSNCreationInfoW |
| 45 | +{ |
| 46 | + DWORD dwSize; |
| 47 | + HWND hwndParent; |
| 48 | + DSN_TYPE DSNType; |
| 49 | + DSN_TYPE DSNRestrictType; |
| 50 | + DWORD dwCIFlags; |
| 51 | + WCHAR szDSNName[_MAX_PATH + 1]; |
| 52 | + LPWSTR szParentDir; |
| 53 | +} ODBC_CREATE_DATASOURCE_INFOW; |
| 54 | + |
| 55 | +BOOL INSTAPI SQLCreateDataSourceExW( |
| 56 | + ODBC_CREATE_DATASOURCE_INFOW * pCreateDSInfoW); |
| 57 | +``` |
| 58 | +
|
| 59 | +## Arguments |
| 60 | +*pCreateDSInfoW* |
| 61 | +[Input] A struct of type `ODBC_CREATE_DATASOURCE_INFOW` see comments for descriptions. |
| 62 | +
|
| 63 | +## Returns |
| 64 | +**SQLCreateDataSourceExW** returns TRUE if the data source is created. Otherwise, it returns FALSE. See [SqlCreateDataSource](./sqlcreatedatasource-function.md#diagnostics) for diagnostic info about error codes when this function returns FALSE. |
| 65 | +
|
| 66 | +## Comments |
| 67 | +The `ODBC_CREATE_DATASOURCE_INFOW` has the following fields: |
| 68 | +
|
| 69 | +*dwSize* |
| 70 | +A `DWORD` containing the size of the struct. |
| 71 | +
|
| 72 | +*hwndParent* |
| 73 | +A handle to the parent directory of the data source. |
| 74 | +
|
| 75 | +*DSNType* |
| 76 | +The type of DSN to create. See [About Drivers and Data Sources](../../admin/about-drivers-and-data-sources.md) to understand what these enums map to. |
| 77 | +
|
| 78 | +*DSNRestrictType* |
| 79 | +The least restricted DSN type allowed. |
| 80 | +
|
| 81 | +*dwCIFlags* |
| 82 | +A mask with bits for either `DSNC_ATTEMPT_CONN` or `DSNC_DRIVER_ONLY`. |
| 83 | +
|
| 84 | +*szDSNName* |
| 85 | +Data source name. |
| 86 | +
|
| 87 | +*szParentDir* |
| 88 | +The parent directory of the data source. |
| 89 | +
|
| 90 | +## Related Functions |
| 91 | +
|
| 92 | +|For information about|See| |
| 93 | +|---------------------------|---------| |
| 94 | +|Creating data sources|[SQLCreateDataSource](./sqlcreatedatasource-function.md)| |
0 commit comments