简体   繁体   中英

how to connect sql server database in C++ code?

I have a project of C++ windows form. Now, I want to store the data in my SQL server database. So, how can I connect my database from inside my C++ code and how to write an insert query?

I used the following code but it throws an exception that cannot open or cannot found the database.

SqlConnection^ con = gcnew SqlConnection();
int i = 0;  

con->ConnectionString = "Data Source=122.179.151.229\EIEXPRESS;Initial Catalog=ICAST_IMS;Uid=developer;pwd=dev@12345";
con->Open();

SqlCommand^ com = gcnew SqlCommand();
com->Connection = con;
com->CommandText = "INSERT INTO image_analysis (nodule_count, nodularity) VALUES (final_nodule_count, 'final_nodularity')";
com->ExecuteNonQuery();

I think your problem it's your connection string, you include an "\\" which is a special character, you need to try doing "\\\\" so the system recognize you're inserting an "\\".

Hope this helps you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM