c++ - 尝试使用 C++ 在 SQL Server 中创建新表时出错
问题描述
这是一个创建与 SQL Server 的连接并尝试创建新表的函数。
我尝试了我能想到的一切,现在我一无所知。与服务器的连接工作正常,但总是出现“无法创建新表”的消息。(我已经尝试查看有关该主题的其他 Stack Overflow 帖子)。
它给了我这个错误:
这是我的主要和错误的图片,它表明一个简单的查询有效:
void DB::runQuery(string SQLQuery)
{
SQLCHAR retConString[1024]; // Conection string
switch (SQLDriverConnect(SQLConnectionHandle, NULL, (SQLCHAR*)"DRIVER={SQL Server}; SERVER=localhost, 1433; DATABASE=myDB; UID=myID; PWD=1234;", SQL_NTS, retConString, 1024, NULL, SQL_DRIVER_NOPROMPT)) {
// Establishes connections to a driver and a data source
case SQL_SUCCESS:
break;
case SQL_SUCCESS_WITH_INFO:
break;
case SQL_NO_DATA_FOUND:
showSQLError(SQL_HANDLE_DBC, SQLConnectionHandle);
retCode = -1;
break;
case SQL_INVALID_HANDLE:
showSQLError(SQL_HANDLE_DBC, SQLConnectionHandle);
retCode = -1;
break;
case SQL_ERROR:
showSQLError(SQL_HANDLE_DBC, SQLConnectionHandle);
retCode = -1;
break;
default:
break;
}
if (retCode == -1)
print("An error occurred");
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, SQLConnectionHandle, &SQLStatementHandle))
// Allocates the statement
print("could not allocate the statement");
if (SQL_SUCCESS != SQLExecDirect(SQLStatementHandle, (SQLCHAR*)SQLQuery.c_str(), SQL_NTS)) {
// Executes a preparable statement
showSQLError(SQL_HANDLE_STMT, SQLStatementHandle);
print("could not execute the statement");
}
else {
char name[256];
int age;
while (SQLFetch(SQLStatementHandle) == SQL_SUCCESS) {
// Fetches the next rowset of data from the result
SQLGetData(SQLStatementHandle, 1, SQL_C_DEFAULT, &name, sizeof(name), NULL);
SQLGetData(SQLStatementHandle, 2, SQL_C_DEFAULT, &age, sizeof(age), NULL);
// Retrieves data for a single column in the result set
cout << name << " " << age << endl;
}
}
}
解决方案
推荐阅读
- javascript - 将前端库导入 wix 网站
- apache-spark - Spark-sql 可以在没有安装 Hive 的情况下工作吗?
- xamarin.android - 我无法在具有编写者权限的 Android (Xamarin) 中创建 doc 或 docx 文件。只读
- python - 读取熊猫数据帧的索引转换为标题
- pandas - Pandas - 按列过滤值会引发错误(ValueError:传递的项目数量错误 3,位置意味着 1)
- typescript - 打字稿如何测试两个泛型是否等效?
- python-3.x - 如何在 Tensorflow 中保存多层感知器模型
- javascript - Ember.js 测试页面自动刷新
- c++ - 为什么 C++ std::string 可以支持日文、法文字符?
- ios - 找不到设备支持文件:iOS