Hi Sir,
Good day to all!
I tried to test my asp.net application over LAN (other computer) but it's failed to connect to the sql server 2005 express edition over LAN (windows authentication). My first webform is the Login.aspx page. (but in my development environment it was connection success, my sql server 2005 express edition installed locally on my computer) Below is my code: (Thank you in Advance)
private bool ValidateUser(string userName, string passWord)
{
SqlConnection conn;
SqlCommand cmd;
string lookupPassword = null;
// Check for invalid userName.
// userName must not be null and must be between 1 and 15 characters.
if ((null == userName) || (0 == userName.Length) || (userName.Length > 15))
{
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of userName failed.");
return false;
}
// Check for invalid passWord.
// passWord must not be null and must be between 1 and 25 characters.
if ((null == passWord) || (0 == passWord.Length) || (passWord.Length > 25))
{
System.Diagnostics.Trace.WriteLine("[ValidateUser] Input validation of passWord failed.");
return false;
}
try
{
// Consult with your SQL Server administrator for an appropriate connection
// string to use to connect to your local SQL Server.
conn = new SqlConnection("server=GD467887\\SQLEXPRESS;Integrated Security=SSPI;database=Irocdb");
conn.Open();
// Create SqlCommand to select pwd field from users table given supplied userName.
cmd = new SqlCommand("Select pwd from users where uname=@userName", conn);
cmd.Parameters.Add("@userName", SqlDbType.VarChar, 25);
cmd.Parameters["@userName"].Value = userName;
// Execute command and fetch pwd field into lookupPassword string.
lookupPassword = (string)cmd.ExecuteScalar();
// Cleanup command and connection objects.
cmd.Dispose();
conn.Dispose();
}
catch (Exception ex)
{
// Add error handling here for debugging.
// This error message should not be sent back to the caller.
System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception " + ex.Message);
}
// If no password found, return false.
if (null == lookupPassword)
{
// You could write failed login attempts here to event log for additional security.
return false;
}
// Compare lookupPassword and input passWord, using a case-sensitive comparison.
return (0 == string.Compare(lookupPassword, passWord, false));
}
Loading
Suthish NairPosted Mar 9, 2011, 6:27 AM
Generate and Find Database Connection String using Visual Studio
jess romeroPosted Mar 9, 2011, 7:11 PM
Amit ChoudharyPosted Mar 9, 2011, 4:04 AM
"server=tcp:GD467887,1433;Integrated Security=SSPI;database=Irocdb"
if yes then go to the system where you have installed the sqlserver and check following:
Open the installed instance that you are using to access the database and click on Remote Connections and select allowed TCP&Named Pipes.
jess romeroPosted Mar 9, 2011, 1:29 AM
Amit ChoudharyPosted Mar 8, 2011, 11:13 PM
The Sql-Server is listening on port 1433 TCP and the dynamic port feature is disabled, from my point of view the firewall blocks the port 1433 TCP. Please check also if the sql-server properly bind to his ip address in the sql server configurationmanager.
for the time being try this:
Try specifying a port in connectionstring (for e.g.
<add name="MaximumASPSqlServer" connectionString="Server=tcp:MCMS2005DBLIVE,1433;user id=xyz;password=abc;database=MCMS"/>
)orOpen the installed instance that you are using to access the database and click on Remote Connections and select allowed TCP&Named Pipes.
Hope this helps you.
Thanks