I have a form in which you can enter your email and then receives instructions on resetting the password. It has a textbox (txtEmail), a Submit button (btnResetPassword
) and a lblMessage
.
My C# code looks like this:
protected void btnResetPassword_Click(object sender, EventArgs e)
{
string CS = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand cmd = new SqlCommand("spResetPassword", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter paramEmail = new SqlParameter("@Email", txtEmail.Text);
cmd.Parameters.Add(paramEmail);
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
if (Convert.ToBoolean(rdr["ReturnCode"]))
{
SendPasswordResetEmail(rdr["Email"].ToString(), rdr["UniqueId"].ToString());
lblMessage.Text = "An email with instructions to reset your password is sent to your registered email";
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Username not found!";
}
}
}
}
I then have a method SendPasswordResetEmail(string email, string ID)
which works fine (SMTP).
The stored procedure is:
CREATE PROC Spresetpassword @Email NVARCHAR(100)
AS
BEGIN
DECLARE @UserId INT
SELECT @UserId = id
FROM dbo.turiststbl
WHERE email = @Email
IF (@UserId IS NOT NULL)
BEGIN
--If username exists
DECLARE @GUID UNIQUEIDENTIFIER
SET @GUID = Newid()
INSERT INTO tblresetpasswordrequests (id, userid, resetrequestdatetime)
VALUES (@GUID, @UserId, Getdate())
SELECT
1 AS ReturnCode,
@GUID AS UniqueId,
@Email AS Email
END
ELSE
BEGIN
--If username does not exist
SELECT
0 AS ReturnCode,
NULL AS UniqueId,
NULL AS Email
END
END
When I enter my email, I get the following error:
What can I do?
Edit: Database files are not local, they are on a remote server