I am following this example to understand how to use a DataGridView component can be used to display and manipulate a database table.
I have configured the database access through a Data Connection using Tools->Connect to Database menu in Visual Studio 2017.
Now I am trying to get the Sqlconnection using the name of that connection configured through the Visual Studio, but I do not know if I need to hardcode the connection string or it shall be retrieved from the configuration.
I have tried this:
Dim DBConnection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("localhost(wildfire)").ConnectionString)
and this:
Dim DBConnection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("wildfire").ConnectionString)
In both cases I get:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Configuration.ConnectionStringSettingsCollection.this[string].get returned Nothing.
What shall I do to get the connection string? Do I need to hardcode it in the source code?
Note: I tag the question also in C# in case the answer is similar. I can convert the syntax from C# to VB if the way to retrieve the connection string is similar.