Resolved Error connecting to server

OmriDulla

New member
Joined
Nov 19, 2023
Messages
4
Programming Experience
1-3
I am trying to connect to server and get data from database, here is the code:
code.png


But I am getting "Connection must be valid and open." error when cmd.ExecuteReader();

Here is the error:
error.png


Note: My Ip is added to remoteSQL, and connection opens, the error is when cmd.ExecuteReader();
 
It's the connection or the construction of the connection that makes the difference. It's the passing on of the connection to the command object that will make the difference.

In the future, please post your code as text in code tags (eg. the button that looks like </> on the toolbar), instead of as a screenshot. That makes it a lot easier for people to help you out in case they want to copy and paste your code to do some testing, or if we happen to be on our mobile rather than our PC. Viewing images is much harder on smaller devices.
 

Latest posts

Back
Top Bottom