Note that there are some explanatory texts on larger screens.

plurals
  1. POWebException was unhandled when reading from database
    primarykey
    data
    text
    <p>What I am doing is very simple. I just need to connect to a SQL database and read the information from the table. I am sure that I am missing something silly. I am using C#, SQL Sever, and WPF. The connectionstring shown is the one that the data source builder provided so I assume it is correct. I tested the connection with it and it was successful. I am attaching some code and images to help you help me solve my problem. </p> <p>Code:</p> <pre><code>private void UserControl_Loaded(object sender, RoutedEventArgs e) { con = new System.Data.SqlClient.SqlConnection(); con.ConnectionString = "Data Source=USSW7DEVWS16\\DEVELOPER;Initial Catalog=acrGIS;Integrated Security=True"; con.Open(); using (SqlCommand command = new SqlCommand("SELECT * FROM dbo.acrObjects", con)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { string Object = reader.GetString(0); string Comment = reader.GetString(1); string OStreet = reader.GetString(2); string OCity = reader.GetString(3); string OState = reader.GetString(4); string OZip = reader.GetString(5); string OSpec = reader.GetString(6); arcObjects.Add(new acrObject() { Object_Num = Object, Comments = Comment, Street = OStreet, City = OCity, State = OState, Zip = OZip, Spec = OSpec }); } foreach (acrObject objects in arcObjects) { MessageBox.Show(objects.ToString()); } } </code></pre> <p>Here is my Class as well as my List and Connection Definitions:</p> <pre><code>class acrObject { public string Object_Num {get; set;} public string Comments{get; set;} public string Street {get; set;} public string City {get; set;} public string State{get; set;} public string Zip {get; set;} public string Spec {get; set;} public override string ToString() { return string.Format("Object Number: {0}, Comments: {1}, Street: {2}, City: {3}, State: {4}, Zip: {5}, Spec: {6}", Object_Num, Comments, Street, City, State, Zip, Spec); } } System.Data.SqlClient.SqlConnection con; List&lt;acrObject&gt; arcObjects = new List&lt;acrObject&gt;(); </code></pre> <p>Images of the exception:</p> <p><img src="https://i.stack.imgur.com/Mds0d.png" alt="enter image description here"></p> <p>It happens on the line:</p> <pre><code>while (reader.Read()) </code></pre> <p>What is even more weird is sometimes the error is not thrown and it skips all of the code. So it never evens tries to show the messagebox which I find is so weird. Thank you for your help. If you have any more questions or would like me to post more of my code let me know and I will be happy to. </p> <p>Showing Breakpoint and Call Stack:</p> <p><img src="https://i.stack.imgur.com/K6Snr.png" alt="enter image description here"></p> <p>Here is the exception thrown when I perform a try/catch:</p> <p><img src="https://i.stack.imgur.com/oUbxt.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload