iam running asp.mvs web-application.
its already hosted and DB is also by same hosting provider.
i am trying (already 3 day) to use given connection string for transfering data from DB.
here is my method where is my connection string.
can you please take a look and see some potential mistake.
its very annoing because i cant do this simple thing.
/// <summary>
/// Gets connection string of Database
/// </summary>
/// <returns>connection string of type const</returns>
public static string GetConnectionStringOfDatabase()
{
try
{
string cnc = @"data source=OnlineVertrag.mssql.somee.com;workstation id=OnlineVertrag.mssql.somee.com;packet size=4096;user id="xxx";pwd="xxx";persist security info=False;initial catalog=OnlineVertrag";
return cnc;
}
catch (Exception ex)
{
bool rethrow = ExceptionHelper.Handle(ex, "Business Logic");
if (rethrow)
{
throw;
}
}
return null;
}
public bool CheckIfUserIsActive(string username)
{
SqlConnection connection = new SqlConnection(SQLDataHelper.GetConnectionStringOfDatabase());
try
{
connection.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @"SELECT IsActive "
+ "FROM Users "
+ "WHERE Username = @Username";
cmd.Parameters.Add(new SqlParameter("@Username", UserName));
SqlDataReader reader = cmd.ExecuteReader();
bool isActiveValueFromDataBase = false;
if (reader.HasRows)
{
while (reader.Read())
{
isActiveValueFromDataBase = Convert.ToBoolean(reader["IsActive"]);
if (isActiveValueFromDataBase == true)
{
return true;
}
return false;
}
}
reader.Close();
}
Mistake #1: Posting login information in a public forum.
Seriously – everybody who views this page and looks at the edit history of the question can now login to your database. You should change the password ASAP.
Mistake #2: Storing a connection string in code. As you just saw – password changes can come quite unexpectedly. Easiest way: store in the web.config and use ConfigurationManager.ConnectionStrings to access them:
http://pietschsoft.com/post/2005/12/28/ASPNET-20-How-to-get-a-specific-ConnectionString-from-the-WebConfig-by-name.aspx
Possible mistake #3: Try “data source=OnlineVertrag.mssql.somee.com;user id=xxx;pwd=xxx;initial catalog=OnlineVertrag”. Maybe the spaces between “workstation” and “id” are the problem.