A
A
Anton2016-01-08 05:00:04
C++ / C#
Anton, 2016-01-08 05:00:04

How to fix "ConnectionString property not initialized"?

Hello!
An error occurs:

ConnectionString property not initialized

For example, the program has the addition of news. If you submit an empty form, you will get an error saying that the fields are empty. These are their own checks that prevent the execution of an "empty" request.
If you immediately click on the same button again (add news), then instead of the previous error, a catch will already appear in the form:
0df5d51851f3402cba8da54988807cdc.png
Here's how to fix it?
Inside public partial class NewsWindow : WindowI write:
SqlConnection sqlConnection = new SqlConnection(@"Server=(local);Database=DB_NAME;Trusted_Connection=Yes;");

Further, I wrap all SqlCommand (INSERT, SELECT) in a using statement. Example:
using (SqlCommand sqlCommand = new SqlCommand("SELECT TOP(10) id, title, text, date FROM news ORDER BY id DESC", sqlConnection))
// ...

What could be the problem and how to fix it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question