Probably the worst part about using Microsoft Access and SQL is trying to connect through the OLEDB connection. The code is on the one drive and has been working without issue but this morning it has came up with this error;
"System.InvalidOperationException: 'The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.'"
Previously I was able to change the CPU from any to x86 which sometimes seemed to fix the problem but now it is not. I am running System.Data.OleDb 7.0.0 which I have not changed since starting this protect.
using System.Data.OleDb;
using System.Data;
using System;
namespace LOGIN_TAKE_FIVE
{
public partial class Form1 : Form
{
OleDbConnection connection = new OleDbConnection();
public Form1()
{
InitializeComponent();
connection.ConnectionString = (#"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:/Users/kiera/LOGIN TAKE FIVE/bin/Debug/net6.0-windows/dbNumber2.accdb");
}
private void btnAdd_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand cmd = new OleDbCommand();
string encryptUser = EncryptString(tbUsername.Text);
string encryptPassword = EncryptString(tbPassword.Text);
string regSQL = "INSERT INTO Users ([Username], [Password]) VALUES ('" + encryptUser + "', '" + encryptPassword + "')";
cmd = new OleDbCommand(regSQL, connection);
cmd.ExecuteNonQuery();
connection.Close();
}
this code was working in full no less than 5 days ago so I am unsure what the problem is. Any help would be greatly appreciated.
Related
Hi i'm new to this c# coding and i've created an application but it on shows up in task manager on another machine and just won run. I've googled and did all that it says with Net framework version and all.
I am thinking maybe it has something to do with my combo box using a file path to get to the external database.
Here is my code with the comcbox:
private void combox_txt_SelectedIndexChanged(object sender, EventArgs e)
{
string connectionString = String.Format(#"Provider=Microsoft.ACE.OLEDB.12.0;" + #"Data Source=C:\Users\Chavoy\Documents\Dougie Company\Application Files\Douglas.Gas.xlsx;Extended Properties='Excel 12.0;HDR=YES;IMEX=0;READONLY=FALSE'");
using (OleDbConnection cn = new OleDbConnection(connectionString))
{
cn.Open();
OleDbCommand cmd1 = new OleDbCommand("SELECT * FROM [Cust$] WHERE CustomerName = '" + combox_txt.Text + "' ", cn);
OleDbDataReader reader = cmd1.ExecuteReader();
while (reader.Read())
{
custid_txt.Text = reader["CustomerID"].ToString();
name_txt.Text = reader["CustomerName"].ToString();
tel_txt.Text = reader["TelephoneNumber"].ToString();
address_txt.Text = reader["Address"].ToString();
sizegas_txt.Text = reader["Size_of_Gas"].ToString();
}
}
}
As you can see my path contains my user name and such... but how can i get it to be the other machine username?
That's probably because Microsoft Access Database Engine is not installed on that machine.
Are you sure you have the right .NET framework installed on the computer?
If you are using Visual Studio, you can find the framework version by right clicking your project>Properties>Target Framework.
I’m very new to ASP.net and have been following a few video tutorials to build a log in page. I successfully created my registration page fine that enters details into my table within the database fine however I can't get my log in page to work =/.I’ve been at this for a few hours and am not sure if any of you can help but it's worth a shot. The IDE I am using is visual studio (latest version).
I am getting the following error (clicking the image will give a closer view, but you probably already know that):
the error changes depending on who I try to log on as for example the above error was returned when trying to log in as john, the below error was returned trying to log in as admin.
shown below is my code used behind the log in button:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from [Table] where [Login]'" + Loginbox.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
conn.Close();
if (temp == 1)
{
conn.Open();
string CheckPasswordQuery = "select Password from [Table] where [Login]='" + Loginbox.Text + "'";
SqlCommand Passcom = new SqlCommand(CheckPasswordQuery, conn);
string password = Passcom.ExecuteScalar().ToString().Replace(" ","");
if (password == Passwordbox.Text)
{
Session["New"] = Passwordbox.Text;
Response.Write("Password is correct");
}
else
{
Response.Write("Wrong password");
}
}
else {
Response.Write("User name does not exist");
}
}
}
Shown below is the form page view, which runs perfectly fine, the error gets returned when the log in button is pressed.
Shown below is the table definition:
And shown below is the data contained within the table:
Thank you all for your time and I appreciate any input any of you have to help solve this.
You have invalid syntax in your query. Please note that while many tutorials may show you to query like this, it's very insecure. You should use parameters. However, for the sake of this answer, you forgot the equal sign:
string checkuser = "select count(*) from [Table] where [Login] = '" + Loginbox.Text + "'";
Your syntax is incorrect, but it is actually safer if you parameterize it to avoid sql injection
string checkuser = "select count(*) from [Table] where [Login] = #user";
SqlCommand com = new SqlCommand(checkuser, conn);
com.Parameters.Add("#user", Loginbox.Text);
...
I would like to create a simple registration form for WINDOWS application. I am using SQLite database which can be embedded into the project as I need to create a .exe file and mail it to my friend.
Now my registration form has 2 text boxes.
textBox1 for name
textBox2 for password
I need to insert these 2 values into the table and I have written the following code.
using Finisar.SQLite;
namespace Task_Sa
public partial class Form2 : Form
{
string connectionString;
public Form2()
{
InitializeComponent();
connectionString = #"Data Source=database.db;Version=3;New=True;Compress=True;";
}
private void button1_Click(object sender, EventArgs e)
{
using (SQLiteConnection sqlite_conn = new SQLiteConnection(connectionString))
{
SQLiteCommand cmd = new SQLiteCommand();
cmd.CommandText = #"INSERT INTO TaskTable(UserName,PassWord) values(#userName,#passWord)";
cmd.Connection = sqlite_conn;
cmd.Parameters.Add(new SQLiteParameter("#userName",textBox1.Text)); -> ERROR
}
}
}
}
here I am getting the error as the parameters are not matching. 2 parameters should be of type string and dbType. Please help me to complete the code in this regard. I have copied and pasted SQLite dll file in debug folder of my project and I also have used the " using Finisar.SQLite; " name space.
Try this
cmd.CommandText = "INSERT INTO TaskTable(UserName,PassWord) values('"+ textBox1.Text +"','"+ textBox2.Text +"')";
Add a blank space before TaskTable and values:
Your version:
cmd.CommandText = #"INSERT INTO TaskTable(UserName,PassWord) values(#userName,#passWord)";
Modified version:
cmd.CommandText = #"INSERT INTO TaskTable (UserName,PassWord) values (#userName,#passWord)";
I'm developing a Windows CE app in C# and trying to connect to an Oracle database. I'm using CoreLab.Oracle reference. This is my code:
using CoreLab.Oracle;
namespace SmartDeviceProject1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OracleConnection conn = new OracleConnection();
conn.ConnectionString = "User ID=name;Password=pass;Host=ip;Pooling=true;Min Pool Size=0;Max Pool Size=100;Connection Lifetime=0;Port=1522;Sid=bleh;Unicode=True";
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "Select * from dc_emp ";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
label1.Text = dr.GetString(0);
conn.Dispose();
}
}
}
Every time I run the project conn.Open(); gets error : Network error:: A Socket operation was attempted to an unreachable host. So something is wrong with my connection string but I don't know what.
I might add that when I drag and drop a "oracleConnection" component to my form in design mode and edit the properties, my connection is created.
I have read in some forums I must set the "direct" property to true in my connection string, but when I add it to my connection string it says : Unknown connection string parameter Direct
Can someone please help me?
This is now working! FINALLY FIGURED IT OUT. Had to install Virtual PC 2007 for the VS Emulators. Then configure the Emulator to use the virtual network card.
I created a database in sql server express edition, in that i create a table called employee. Now i am able to inserting rows(records) dynamically into table successfully, and i can also read those records successfully. But the problem is the values which are inserted dynamically are stored temporarily. When i close and reopen the application the previous inserted records are not available. can u please suggest me what can i do to save records permanently into the database.
thanking you.....
This is my code used to inserting the records into sql server database. Please help me out of this problem...
namespace VACS_practice
{
public partial class Form1 : Form
{
string m_sVehicleNo, m_sName, m_sFlatNo, m_sImagpath;
System.Data.SqlClient.SqlConnection Con;
System.Data.SqlClient.SqlCommand Cmd;
string ConString = #"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\VACSDB.mdf;Integrated Security=True;User Instance=True";
public Form1()
{
InitializeComponent();
}
private void btnAddClick(object sender, EventArgs e)
{
Con = new SqlConnection(ConString);
m_sVehicleNo = m_VehicleNo.Text;
m_sName = m_Name.Text;
m_sFlatNo = m_Phno.Text;
//m_sImagpath = m_ImgPath.Text;
Cmd = new SqlCommand("INSERT INTO ResidentDB ([R_VehNo],[R_Name],[R_PhNo]) VALUES ('" + m_sVehicleNo + "','" + m_sName + "','" + m_sFlatNo + "')", Con);
Con.Open();
Cmd.ExecuteNonQuery();
Con.Close();
MessageBox.Show("Inserted successfully");
// this.Close();
}
Almost certainly you are not committing your changes. If you are running transactions then you must commit.
Alternatively, you are making changes in your in-memory versions, that are not connected to the database at all.