I am trying to connect to a new mssql server via server management studio. Now i am able to login with the details through windows authentication into the database.
The challenge is i can't connect to the database from my aspx pages with the login details displayed on the server management studio.
When i tried login i got this error
Error Logging in Login failed for user 'SK-PACK\skylane003$'.
My code
public partial class Welcome : System.Web.UI.Page
{
SqlCommand cmd1 = new SqlCommand();
SqlCommand cmd99 = new SqlCommand();
SqlConnection conn99 = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlConnection dbConn = new SqlConnection();
SqlDataReader dr;
string selectSQL;
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
Session["username"] = TextBox1.Text;
selectSQL = "select * from users WHERE " + "username = @username AND password = @password ";
dbConn.ConnectionString = "data source=skylane003 Initial Catalog=gaming;Integrated Security=True;";
cmd.Connection = dbConn;
cmd.CommandText = selectSQL;
cmd.CommandType = CommandType.Text;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@username", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@password", Encrypt(TextBox2.Text.Trim()));
try
{
dbConn.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
DateTime date1 = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy hh:mm tt"));
Session["date"] = date1;
string insertSQL;
insertSQL = "INSERT INTO usertracking (";
insertSQL += "username,loggedin)";
insertSQL += "VALUES('";
insertSQL += TextBox1.Text + "','";
insertSQL += date1 + "')";
String connectionString = "data source=skylane003 Initial Catalog=gaming;Integrated Security=True;";
SqlConnection con1 = new SqlConnection(connectionString);
SqlCommand cmd1 = new SqlCommand(insertSQL, con1);
int added = 0;
try
{
con1.Open();
added = cmd1.ExecuteNonQuery();
if (added == 1)
{
}
else
{
Label1.Text = "Error @ unit 7";
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
con1.Close();
}
Response.Redirect("Home.aspx");
}
else
{
Label1.Text = "Sorry You Can't Login ";
}
dr.Close();
}
catch (Exception err)
{
Label1.Text = "Error Logging in ";
Label1.Text += err.Message;
}
finally
{
dbConn.Close();
}
}
}
please help