Click here to Skip to main content
15,896,359 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have resotred database when i conect sql it show server name blank i enterd [.] dot it connect.
when i run my asp.net web application its show instance error.

my connection string is:
<add name="WarehouseWebsiteString" connectionString="Data Source=hostingmssql10;Network Library=dbmssocn;Connection Timeout=15;Packet Size=4096;Integrated Security=no;User ID=bea3de-warehousebissdscom; Encrypt=no;Initial Catalog=bea3de-warehousebissdscom; Password=1234;"
providerName="System.Data.SqlClient"/>

i have create login page using database but it not login give error

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Web.Configuration;


public partial class AdminLogin : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["WarehouseWebsiteString"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
error.Visible = false;

}

protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e)
{
try
{
using (con = new SqlConnection(WebConfigurationManager.ConnectionStrings["WarehouseWebsiteString"].ToString()))
{

//string username = txtUserName.Text;
//string password = txtPassword.Text;

con.Open();
string qry = "select * from tblLoginDetails where UserName='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'";
SqlCommand cmd = new SqlCommand(qry, con);
int count = Convert.ToInt32(cmd.ExecuteScalar());

if (count == 1)
{
Session["UserName"] = txtUserName.Text.Trim();
Response.Redirect("~/Admin/Default.aspx");
error.Visible = false;
}
else
{
error.Visible = true;

}


}
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}


}
}

but it not work i dont understand where i do change.
Posted
Updated 2-May-18 2:47am
Comments
F-ES Sitecore 4-Apr-18 6:40am    
You have to make sure the datasource parameter is correct for the sql database you're connecting to and we can't tell you what that is, you have access to it and we don't. It could be you're missing the instance name (something like myserver\sql2016) but again we don't know if your server uses an instance name or not. If using the dot works then stick with that.
Afzaal Ahmad Zeeshan 4-Apr-18 7:00am    
Do you get any error?
Dave Kreskowiak 4-Apr-18 8:21am    
Your connection string is wrong, but since you haven't shown us that string, it's impossible to tell you exactly what's wrong with it.

Oh, and don't reply to posts by typing your reply into a Solution. Hover the mouse over the post you want to reply to and a Reply button will show up. Click that.
Richard Deeming 4-Apr-18 12:13pm    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]


NEVER store passwords in plain text:
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]


And why are you re-inventing the wheel? ASP.NET has several perfectly good authentication systems built-in - for example, ASP.NET Identity[^]

1 solution

When i do this in configration file It working properly:-

<connectionStrings>
  <!--<add name="WarehouseWebsiteString" connectionString="Data Source=BISWEBSERVER\SQLSERVER2005; DataBase=Warehouse; User Id=sa; Password=xfiles_76;"/>-->
  <add name="WarehouseWebsiteString" connectionString="Data Source=. ;Network Library=dbmssocn;Connection Timeout=15;Packet Size=4096;Integrated Security=no;User ID=warehousebissdscom; Encrypt=no;Initial Catalog=warehousebissdscom; Password=123;Trusted_Connection=true;"/>
</connectionStrings>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900