Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When trying to insert database objects from my access(2016) to my C#(2015), I am getting a continuous error when I click finish of ...

one or more errors occurred while processing the database objects
<newuser>
Could not retrieve schema information for table or view NewUser.'


This is my current code...
Is anyone able to help me with this?

C#
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\DatabaseEmployees.accdb;Persist Security Info=True");
OleDbCommand command = new OleDbCommand();

int i = 0;
if (IDtbx.Text == string.Empty)
{
MessageBox.Show("Please log in");
}
command = new OleDbCommand("select count(*)from NewUser where Username= '" + IDtbx.Text + "' AND Password= '" + PSWtbx.Text + "'", connection);

if (connection.State == ConnectionState.Closed)
{
connection.Open();
i = (int)command.ExecuteScalar();
}

connection.Close();
if (i > 0)
{
MainSystem mainForm = new MainSystem();
mainForm.FormClosed += new FormClosedEventHandler(Login_FormClosed);
mainForm.Show();
this.Hide();
LoginError.Visible = false;
}

else
{
LoginError.Visible = true;
}

}


What I have tried:

I have tried using all three of my other databases linked to C#, deleting the database and starting again
Posted
Updated 11-Nov-17 22:27pm
v2
Comments
Suvendu Shekhar Giri 11-Nov-17 10:45am    
Are you sure your table name is "NewUser"?
Usually, people name it as "Users"/"UserLogins"/others and that's why asking.
Member 13512434 11-Nov-17 11:43am    
Yes I've double checked and it is the correct name that I'm using
Sinisa Hajnal 11-Nov-17 15:29pm    
First of all, you should NEVER paste user input to database query. Google SQL Injection for details.

The error may come from lack of spacing between count(*)from...other than that, is there a schema in Access? Finally, I'd use SQL Express rather than Access :)
Member 13512434 12-Nov-17 7:45am    
Sorry, what do you mean by schema in Access please? I'm very new to this

1 solution

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900