问题描述
我正在尝试开发数据库迁移实用程序.
我正在使用以下功能来创建DSN.
SQLConfigDataSource(NULL,ODBC_ADD_DSN,"SQL Server",ss)
此功能的最后一个参数是连接字符串.它的数据类型为LPCSTR.
此函数期望使用NULL字符作为分隔符.
简而言之,它期望字符串采用以下格式.
"ExpTempSQL \ 0SERVER =(本地)\ 0Trusted_Connection =是\ 0 \ 0"
如果您发现它们之间有NULL字符(\ 0).由于这个原因,我无法动态创建此字符串,因为strcat函数无法将字符串与NULL字符连接在一起,它会跳过NULL之后的字符串(我认为这是正确的行为).
在这方面的各种帮助将不胜感激.
Hi,
I am trying to develop a database migration utility.
I am using following function to create DSN.
SQLConfigDataSource(NULL, ODBC_ADD_DSN,"SQL Server",ss)
Last parameter of this fucntion is a connection string. It is of data type LPCSTR.
This function expects NULL character as a seperator.
In short it expects the string in following format.
"ExpTempSQL\0SERVER=(local)\0Trusted_Connection=yes\0\0"
If you notice there are NULL characters (\0) in between. Due to this i am not able to create this string dynamically as strcat function cannot concatenate the string with NULL characters, It skips the string beyond NULL(which is i think the correct behavior).
Help of any sort in this regard will be highly appreciated.
推荐答案
CString sAttributes;
//Form the attributes string
sAttributes += "DSN=";
sAttributes += YOUR DSN NAME;
sAttributes += ''\0'';
sAttributes += "Server=";
sAttributes += SERVER NAME;
sAttributes += ''\0'';
您可以对其他属性执行相同的操作.
You can do the same for extra attributes.
struct testfunctor
{
void operator()(char& c) { if(c == ''|'') c = ''\0''; }
};
std::for_each( str.begin(), str.end(), testfunctor() );
这应该可行.
This should work..
这篇关于需要将两个字符串与NULL字符连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!