Permalink
Browse files

Fix error where database is not open

  • Loading branch information...
1 parent 921bf94 commit 1c6cab19f9029673cd98ba8624bf9cc91d04bae9 @hpapaxen hpapaxen committed Feb 22, 2014
Showing with 37 additions and 0 deletions.
  1. +37 −0 WebGoat/App_Code/DB/SqliteDbProvider.cs
View
37 WebGoat/App_Code/DB/SqliteDbProvider.cs
@@ -59,6 +59,8 @@ public DataSet GetCatalogData()
{
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter("select * from Products", connection);
DataSet ds = new DataSet();
@@ -79,6 +81,8 @@ public bool IsValidCustomerLogin(string email, string password)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
//TODO: User reader instead (for all calls)
@@ -132,6 +136,8 @@ public string CustomCustomerLogin(string email, string password)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
da.Fill(ds);
@@ -179,6 +185,8 @@ public string GetCustomerEmail(string customerNumber)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select email from CustomerLogin where customerNumber = " + customerNumber;
SqliteCommand command = new SqliteCommand(sql, connection);
output = command.ExecuteScalar().ToString();
@@ -204,6 +212,8 @@ public DataSet GetCustomerDetails(string customerNumber)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
da.Fill(ds);
}
@@ -224,6 +234,8 @@ public DataSet GetOffice(string city)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select * from Offices where city = @city";
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
da.SelectCommand.Parameters.AddWithValue("@city", city);
@@ -237,6 +249,8 @@ public DataSet GetComments(string productCode)
{
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select * from Comments where productCode = @productCode";
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
da.SelectCommand.Parameters.AddWithValue("@productCode", productCode);
@@ -279,6 +293,8 @@ public string UpdateCustomerPassword(int customerNumber, string password)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteCommand command = new SqliteCommand(sql, connection);
int rows_added = command.ExecuteNonQuery();
@@ -304,6 +320,8 @@ public string[] GetSecurityQuestionAndAnswer(string email)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
@@ -328,6 +346,8 @@ public string GetPasswordByEmail(string email)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
//get data
string sql = "select * from CustomerLogin where email = '" + email + "';";
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
@@ -356,6 +376,8 @@ public DataSet GetUsers()
{
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select * from CustomerLogin;";
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
@@ -369,6 +391,8 @@ public DataSet GetOrders(int customerID)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select * from Orders where customerNumber = " + customerID;
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
@@ -390,6 +414,8 @@ public DataSet GetProductDetails(string productCode)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
sql = "select * from Products where productCode = '" + productCode + "'";
da = new SqliteDataAdapter(sql, connection);
da.Fill(ds, "products");
@@ -422,6 +448,8 @@ public DataSet GetOrderDetails(int orderNumber)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
da.Fill(ds);
@@ -437,6 +465,8 @@ public DataSet GetPayments(int customerNumber)
{
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select * from Payments where customerNumber = " + customerNumber;
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
@@ -469,6 +499,7 @@ public DataSet GetProductsAndCategories(int catNumber)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
sql = "select * from Categories" + catClause;
da = new SqliteDataAdapter(sql, connection);
@@ -497,6 +528,8 @@ public DataSet GetEmailByName(string name)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
da.Fill(ds);
@@ -516,6 +549,8 @@ public string GetEmailByCustomerNumber(string num)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
string sql = "select email from CustomerLogin where customerNumber = " + num;
SqliteCommand cmd = new SqliteCommand(sql, connection);
output = (string)cmd.ExecuteScalar();
@@ -538,6 +573,8 @@ public DataSet GetCustomerEmails(string email)
using (SqliteConnection connection = new SqliteConnection(_connectionString))
{
+ connection.Open();
+
SqliteDataAdapter da = new SqliteDataAdapter(sql, connection);
DataSet ds = new DataSet();
da.Fill(ds);

0 comments on commit 1c6cab1

Please sign in to comment.