SQL 使用 C++/CLI 的服务器
SQL Server with C++/CLI
我正在尝试从托管 C++ 代码连接到 SQL 服务器。但是我无法与 SQL 服务器建立连接。我从 Visual Studio 和 copied/pasted 连接字符串连接到 SQL 服务器。此连接字符串当前也适用于 C# 应用程序。
我的代码如下:
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <system.data.dll>
#include <tchar.h>
#include "SqlServer.h"
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
using namespace System::Xml;
bool getAllUsers()
{
SqlConnection^ connection;
//SqlDataAdapter^ dataAdapter;
//DataSet^ dataSet;
SqlDataReader^ dataReader;
SqlCommand^ sqlCommand;
connection = gcnew SqlConnection("Data Source=(local)\OMEGA;Initial Catalog=Omega;Integrated Security=True");
//dataAdapter = gcnew SqlDataAdapter();
//dataSet = gcnew DataSet();
sqlCommand = gcnew SqlCommand("select * from applicationuser", connection);
connection->Open();
dataReader = sqlCommand->ExecuteReader();
while (dataReader->Read())
{
Console::WriteLine(dataReader->GetSqlString(0));
}
connection->Close();
return true;
}
反斜杠'\'在'OMEGA'之前没有转义。试试 \\OMEGA .
我正在尝试从托管 C++ 代码连接到 SQL 服务器。但是我无法与 SQL 服务器建立连接。我从 Visual Studio 和 copied/pasted 连接字符串连接到 SQL 服务器。此连接字符串当前也适用于 C# 应用程序。
我的代码如下:
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.dll>
#using <system.data.dll>
#include <tchar.h>
#include "SqlServer.h"
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
using namespace System::Xml;
bool getAllUsers()
{
SqlConnection^ connection;
//SqlDataAdapter^ dataAdapter;
//DataSet^ dataSet;
SqlDataReader^ dataReader;
SqlCommand^ sqlCommand;
connection = gcnew SqlConnection("Data Source=(local)\OMEGA;Initial Catalog=Omega;Integrated Security=True");
//dataAdapter = gcnew SqlDataAdapter();
//dataSet = gcnew DataSet();
sqlCommand = gcnew SqlCommand("select * from applicationuser", connection);
connection->Open();
dataReader = sqlCommand->ExecuteReader();
while (dataReader->Read())
{
Console::WriteLine(dataReader->GetSqlString(0));
}
connection->Close();
return true;
}
反斜杠'\'在'OMEGA'之前没有转义。试试 \\OMEGA .