BOOL SQLConfigDataSource(
HWND hwndParent,
WORD fRequest,
LPCSTR lpszDriver,
LPCSTR lpszAttributes);下面这样写正确,ee返回值是1;
但我的SERVER名是不定的, 我想用gethostname()取,
然后拼成串lpszAttributes,做了两天不成,int ee=SQLConfigDataSource(NULL,ODBC_ADD_DSN,
(LPSTR)"SQL Server",
(LPSTR)"DSN=student\0"
"SERVER=px09\0"
"DATABASE=student\0");大家帮我看看吗,我是这样拼的
char *as="DSN=student\0";
char *bs="SERVER=px09\0";
char *cs="DATABASE=student\0";
LPSTR lpszAttributes;strcat(lpszAttributes,as);
strcat(lpszAttributes,bs);
strcat(lpszAttributes,cs);
SQlconfigdatasource(,,,lpszAttributes);//返回值为0
HWND hwndParent,
WORD fRequest,
LPCSTR lpszDriver,
LPCSTR lpszAttributes);下面这样写正确,ee返回值是1;
但我的SERVER名是不定的, 我想用gethostname()取,
然后拼成串lpszAttributes,做了两天不成,int ee=SQLConfigDataSource(NULL,ODBC_ADD_DSN,
(LPSTR)"SQL Server",
(LPSTR)"DSN=student\0"
"SERVER=px09\0"
"DATABASE=student\0");大家帮我看看吗,我是这样拼的
char *as="DSN=student\0";
char *bs="SERVER=px09\0";
char *cs="DATABASE=student\0";
LPSTR lpszAttributes;strcat(lpszAttributes,as);
strcat(lpszAttributes,bs);
strcat(lpszAttributes,cs);
SQlconfigdatasource(,,,lpszAttributes);//返回值为0
strcat(lpszAttributes,bs);
strcat(lpszAttributes,cs); //这样子,'\0'字符被忽略了。
用sprintf吧。
LPSTR lpszAttributes = new TCHAR[1023];//大小看着办
sprintf(lpszAttributes, "%s\0%s\0%s\0\0", as, bs, cs);//不知道成不成,没试。
SQlconfigdatasource(,,,lpszAttributes);//返回值为0