Danish Habib

Danish Habib

  • NA
  • 694
  • 242.8k

I am getting a Network or instance related error with my ap

Oct 12 2015 1:14 AM
I have a application in which in app.config i mentioned my connection string such as 
 
 
<add name="DMS_2008_Data.Properties.Settings.Default.DataConnection"
connectionString="Data Source=ASPKCO-DANISH\SQLEXPRESS1;Initial Catalog=DMS2008;Integrated Security=True;Connect Timeout=30"
providerName="System.Data.SqlClient" />
 
and in code i am using this line
public ClsUserLoging IsValidLog(string UserID, string PassWord)
{
try
{
objClsUsers = null;
con = new SqlConnection(DMS_2008_Data.Properties.Settings.Default.DataConnection.ToString());
con.Open();
com = new SqlCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "SELECT UserName, IsNever, CreateDate, ValidDays, ExpireDate FROM Users WHERE (UserID = @UserID) AND (UserPassWord = @UserPassWord)";
com.Parameters.Add("@UserID", SqlDbType.NVarChar, 30).Value = UserID.ToString().Trim();
com.Parameters.Add("@UserPassWord", SqlDbType.NVarChar, 60).Value = PassWord.ToString().Trim();
reader = com.ExecuteReader();
while (reader.Read())
{
objClsUsers = new ClsUserLoging();
objClsUsers.UserName = reader.GetString(0).ToString();
objClsUsers.Never = reader.GetBoolean(1);
objClsUsers.CreateDate = reader.GetDateTime(2);
objClsUsers.ValidDays = (short)reader.GetInt32(3);
objClsUsers.ExpireDate = reader.GetDateTime(4);
}
reader.Close();
com.Parameters.Clear();
}
catch (Exception ex)
{
objClsUsers = null;
throw ex;
}
finally
{
if (com != null)
com.Dispose();
if (con != null)
con.Dispose();
com = null;
con = null;
}
return objClsUsers;
}
 
I am getting an error a network or instance related error occured and there is not issue with DB and connection string because i am using another web application accessing the same db using web.config please assist  

Answers (12)