mardi 25 mai 2021

Database not working after publishing website on IIS - C# Web Services

Hope you're doing well!

I will try to be brief,

I made a web service called "Contacts.asmx" that have this code:

    [WebMethod]
public DataTable GetContacts()
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers"))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataTable dt = new DataTable())
                {
                    dt.TableName = "Customers";
                    sda.Fill(dt);
                    return dt;
                }
            }
        }
    }

and and I have this code in my web.config

<add name="constr" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\user\Desktop\InternetApp\Folder\database.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>

Seems to be working fine and i'm getting the XML when i click invoke.

But after publishing website on IIS : http://localhost/Contacts, i'm having this problem: enter image description here

What should i do?




Aucun commentaire:

Enregistrer un commentaire