Reputation: 11
For Acccess Database which open with Message "This database has been opended read-only".
For this DB when we connect using C#.net application with OleDbconnectio ..at time of updating Query it give Error "Operation must use an updateable query."
I just want to prompt user if DB opened with ReadOnly Permission In Access Database.. how can we add code in C#.net application to identiy oledb database ReadOnly Permission.
Thanks
Upvotes: 1
Views: 653
Reputation: 19956
As far as I can remember, Access can deny you writes despite the fact that database file is writable.
Best way to check it is to try to insert some dummy value right after opening the database. Catch the exception and inform the user.
Upvotes: 1
Reputation: 31610
You can use FileInfo
FileInfo f = new FileInfo(@"C:\MyDb.accdb");
if (f.IsReadOnly)
{
Console.WriteLine("File is Read only");
}
else
{
Console.WriteLine("File is Not Read Only");
}
Upvotes: 1