我正在运行 asp.mvs 网络应用程序。它已经托管,数据库也由同一托管服务提供商提供。我正在尝试(已经 3 天)使用给定connection string
的从数据库传输数据。这是我的方法,我的方法在哪里,connection string.
请您看一下,看看一些潜在的错误。这很烦人,因为我不能做这个简单的事情。
/// <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();
}