PDS8475
Active member
- Joined
- Jun 25, 2019
- Messages
- 41
- Programming Experience
- Beginner
Hi
I have a connection string for a access database that is reading it's path from a file.
The code for the connection string and SQL query is
I can see that the connection string "FullString" is
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Paul\\Documents\\FixIT.mdb"
However I just get the messagebox saying failed to connect to data source. As well checking the Database file shows that no record has been entered.
I can not figure out why this wont connect.
I have a connection string for a access database that is reading it's path from a file.
The code for the connection string and SQL query is
C#:
string ConString = System.IO.File.ReadAllText("FixIT.con");
ConString = ConString.Replace(System.Environment.NewLine, string.Empty);
string FullString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ConString;
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = FullString;
OleDbCommand cmd = new OleDbCommand("INSERT into Donations (Name, Address, Phone, Email, DateDonated, Type, Make, Model, Notes, EnteredBy) Values(@n, @a, @p. @em, @d, @i, @IT, @m, @MO, @s, @NO)");
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("Failed to connect to data source");
}
finally
{
conn.Close();
}
I can see that the connection string "FullString" is
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Paul\\Documents\\FixIT.mdb"
However I just get the messagebox saying failed to connect to data source. As well checking the Database file shows that no record has been entered.
I can not figure out why this wont connect.