I want to retrieve all the registered users from my application using web service in ASP.NET
. However, I have problem with connection string.
public static String getRegisteredUsers(string usernameCode)
{
string username = "";
SqlConnection con = new SqlConnection("MyDatabaseConnectionString1");
SqlCommand cmd = new SqlCommand("Select Username from Users where usernameCode = '" + usernameCode.ToUpper() + "'", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
username = dr["username"].ToString();
}
dr.Close();
con.Close();
return username;
}
This MyDatabaseConnectionString1
is the connection string that I use for the table that I want to retrieve the information from. It works for that table, but not when it comes to web service.
<add name="MyDatabaseConnectionString1" connectionString= "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Korisnik\Desktop\Fitness\App_Data\MyDatabase.mdf;Integrated Security=True"/>
Should I use the same connection string for web service or it's done somehow differently ?