0

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();
1
  • 1
    Once you get the connection string issue sorted out you are going to find an error in your insert statement also. You are trying to insert final_nodule_count but what is that? It will fail with an invalid column name final_nodule_count Commented Jun 13, 2019 at 15:06

1 Answer 1

2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

This is an ex. of a connection I made "Password=1234;Persist Security Info=True;User ID=sa;Initial Catalog=Entrecom;Data Source=LAPTOP-B2CORTSA\\SQLEXPRESS"... but i see now that u solved your problem, that's nice :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.