[英]Connecting to local database (SQL Server ) in c++
I have a database connection to SQL Server using c++. 我使用c ++与SQL Server建立数据库连接。 I am trying to connect to localdb instance which I created in my SQL Server Management Studio, and the name of database is "filingdb", server is "(localdb)\\filing".
我试图连接到在SQL Server Management Studio中创建的localdb实例,数据库名称为“ filingdb”,服务器名称为“(localdb)\\ filing”。 I copied the code from some other site and trying to query, the problem which I am facing is here as I have shared the error list:
我从其他站点复制了代码并尝试进行查询,由于共享错误列表,这里面临的问题是:
Error 8 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlCommandBuilder *' to 'System::Data::SqlClient::SqlCommandBuilder ^' 143 1 cvtest
Error 6 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlDataAdapter *' to 'System::Data::SqlClient::SqlDataAdapter ^' 139 1 cvtest
Error 4 error C2440: 'initializing' : cannot convert from 'System::Data::DataSet *' to 'System::Data::DataSet ^' 126 1 cvtest
Error 2 error C2440: 'initializing' : cannot convert from 'System::Data::SqlClient::SqlConnection *' to 'System::Data::SqlClient::SqlConnection ^' 125 1 cvtest
Error 3 error C2750: 'System::Data::DataSet' : cannot use 'new' on the reference type; use 'gcnew' instead 126 1 cvtest
System::Data::SqlClient::SqlCommandBuilder
' this is the major issue which I am facing System::Data::SqlClient::SqlCommandBuilder
'这是我面临的主要问题
I have tried other ways too, but I am still getting the same error 我也尝试了其他方法,但是仍然遇到相同的错误
Error 12 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlCommandBuilder *' to 'System::Data::SqlClient::SqlCommandBuilder ^' 140 1 cvtest
Error 10 error C2440: '=' : cannot convert from 'System::Data::SqlClient::SqlDataAdapter *' to 'System::Data::SqlClient::SqlDataAdapter ^' 136 1 cvtest
Error 6 error C2440: 'initializing' : cannot convert from 'System::Data::DataSet *' to 'System::Data::DataSet ^' 126 1 cvtest
Error 3 error C2440: 'initializing' : cannot convert from 'System::Data::SqlClient::SqlConnection *' to 'System::Data::SqlClient::SqlConnection ^' 125 1 cvtest
Error 5 error C2750: 'System::Data::DataSet' : cannot use 'new' on the reference type; use 'gcnew' instead 126 1 cvtest
Error 11 error C2750: 'System::Data::SqlClient::SqlCommandBuilder' : cannot use 'new' on the reference type; use 'gcnew' instead 140 1 cvtest
Error 2 error C2750: 'System::Data::SqlClient::SqlConnection' : cannot use 'new' on the reference type; use 'gcnew' instead 125 1 cvtest
Error 9 error C2750: 'System::Data::SqlClient::SqlDataAdapter' : cannot use 'new' on the reference type; use 'gcnew' instead 136 1 cvtest
Can any one please offer advice on how to solve this problem, any other method of connection, and can any one suggest any good link for future use to register connecting database using SQL Server? 可以请任何人提供有关如何解决此问题的建议以及任何其他连接方法,并且可以建议任何好的链接以供将来使用SQL Server注册连接数据库吗?
As an answer to your need of connection strings: 为了满足您对连接字符串的需求:
LocalDB (SQL Server 2012): LocalDB(SQL Server 2012):
LocalDB named instance : LocalDB命名实例:
Server=(localdb)\MyInstance;Integrated Security=true;
If you want to connect to your local SQL Server you can use " .
" instead of "IP" or name of your server. 如果要连接到本地SQL Server,则可以使用“
.
”代替“ IP”或服务器名称。
通过猜测错误消息,创建任何托管对象时,都必须使用gcnew,即:
System::Data::SqlClient::SqlCommandBuilder^ cmdBuilder = gcnew System::Data::SqlClient::SqlCommandBuilder();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.