Note that there are some explanatory texts on larger screens.

plurals
  1. POOleDbConnection - ExecuteNonQuery requires an open and available Connection. The connection's current state is closed
    primarykey
    data
    text
    <p>What am I doing wrong here? </p> <pre><code>using System.Data; using System.Data.OleDb; namespace myProject.Account { public class DbManager { private OleDbConnection OpenDbConnection() { string connectionString = GetConnectionString(); return new OleDbConnection {ConnectionString = connectionString}; } private string GetConnectionString() { return "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\myDataBase.accdb"; } public void InsertUser(string name, string loginName, string password) { OleDbConnection conn = OpenDbConnection(); OleDbCommand command = new OleDbCommand( "INSERT INTO tblUser (UserName, LoginName, Password) VALUES (@name,@login,@pwd)", Conn); command.Parameters.Add("@name", OleDbType.VarChar).Value = name; command.Parameters.Add("@login", OleDbType.VarChar).Value = loginName; command.Parameters.Add("@pwd", OleDbType.VarChar).Value = password; command.ExecuteNonQuery(); } } } </code></pre> <p>.</p> <p>I got this error:</p> <blockquote> <p>ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.<br> Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p> <p>Exception Details: System.InvalidOperationException: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.</p> <p>Source Error:</p> <p>Line 31: command.ExecuteNonQuery();</p> </blockquote> <p>I have tried to look at some other threads but none have helped:</p> <p><a href="https://stackoverflow.com/questions/3548056/executenonquery-requires-an-open-and-available-connection-the-connections-curr">ExecuteNonQuery requires an open and available Connection. The connection&#39;s current state is closed</a></p> <p><a href="https://stackoverflow.com/questions/5211068/ms-access-db-doesnt-save-changes-after-execution-c">MS Access DB doesnt save changes after execution (C#)</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload