简单的基础问题SqlConfigDataSource()真不好意思问

mybname65319203 2004-05-11 01:02:38
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

...全文
66 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
菜牛 2004-05-12
  • 打赏
  • 举报
回复
strcat(lpszAttributes,as);
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
Kudeet 2004-05-11
  • 打赏
  • 举报
回复
jnlon 2004-05-11
  • 打赏
  • 举报
回复
用ADO数据库把......

4,012

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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