Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to cast object of type 'System.Int32' to type 'System.String'
    primarykey
    data
    text
    <p>I am trying to create a very basic connection to an SQLServer 2008 database via a WCF service application for testing purposes. I am receiving the following error when trying to access the service remotely.</p> <blockquote> <p>Unable to cast object of type 'System.Int32' to type 'System.String'</p> </blockquote> <p>Here is my code:</p> <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class GetCustomers : IGetCustomers { // TODO: Implement the collection resource that will contain the SampleItem instances public List&lt;Customer&gt; GetCusts() { List&lt;Customer&gt; mylist = new List&lt;Customer&gt;(); using (SqlConnection conn = new SqlConnection("server=(local);database=BillingTest; Integrated Security=true;")) { conn.Open(); string cmdStr = String.Format("select firstname, lastname, address from Customers");//, lastname, address, city, state,zipcode,phone, email SqlCommand cmd = new SqlCommand(cmdStr, conn); SqlDataReader rd = cmd.ExecuteReader(); if (rd.HasRows) { Customer cust = new Customer(); while (rd.Read()) cust.setCustomer(rd.GetString(0), rd.GetString(1), rd.GetString(2)); mylist.Add(cust); } conn.Close(); } return mylist; } } public class Customer { public string firstname { get; set; } public string lastname { get; set; } public string street { get; set; } public void setCustomer(string first, string last, string street) { // TODO: Complete member initialization this.firstname = first; this.lastname = last; this.street = street; } } </code></pre> <p>This is my first attempt at working with WCF services and sql and I am un-aware of what exactly might be the problem. The firstname, lastname, and address columns of the database are all varchar(50) and I am not trying to access any Int32 columns so I am confused as to where the error is coming from</p>
    singulars
    1. This table or related slice is empty.
    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.
    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