SOLUTION
The Access File .mdb is readonly, from sourcecontrol
Change it on startup with the following Helper: RemoveReadOnlyFlagAccessFile()
Code Snippet to remove ReadOnly
public static string RemoveReadOnlyFlagAccessFile()
{
string returnValue = "";
string connString = GetAccessConnectionString();
if (string.IsNullOrEmpty(connString))
{
returnValue = "ConnectionString not found";
}
else
{
//FORMAT
//connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\AccessFile\oracle-reverse-engineered-modified-manually.mdb;User Id=admin;Password=;"
if (connString.ToUpper().Contains("OLEDB") == false)
{
returnValue = "ConnectionString is not for MsAccess. doesnt contain OLEDB. ConnString: " + connString;
}
else
{
int indexStart = connString.IndexOf("Data Source=");
if (indexStart <= 0)
{
returnValue = "ConnectionString is not correct. doesnt contain Data Source=. ConnString: " + connString;
}
else
{
string tempString = connString.Substring(indexStart + 12);
int indexEnd = tempString.IndexOf(".mdb");
if (indexEnd <= 0)
{
returnValue = "ConnectionString is not correct. doesnt contain .mdb. TempConnString" + tempString;
}
else
{
string filePath = tempString.Substring(0, indexEnd + 4);
string fullPath = Path.GetFullPath(filePath);
if (File.Exists(fullPath) == false)
{
returnValue = "File doesnt exist: " + fullPath;
}
else
{
returnValue = "File " + fullPath + " is: " + File.GetAttributes(fullPath).ToString() + "\n";
try
{
File.SetAttributes(fullPath, FileAttributes.Normal);
returnValue += "File " + fullPath + " NOW is: " + File.GetAttributes(fullPath).ToString() + "\n";
}
// TODO catch explicit exception
catch (Exception ex)
{
Logger.Write("EXCEPTION in File.SetAttributes: " + ex.ToString());
returnValue += "Exception on File.SetAttributes";
}
}
}
}
}
}
//Logger.Write("FileUtils.RemoveReadOnlyFlagAccessFile returnValue: \n" + returnValue);
return returnValue;
}
private static string GetAccessConnectionString()
{
if (System.Configuration.ConfigurationManager.ConnectionStrings.Count == 0)
{
throw new ApplicationException("Set ConnectionString in .config file!");
}
if (System.Configuration.ConfigurationManager.ConnectionStrings.Count == 1)
{
return System.Configuration.ConfigurationManager.ConnectionStrings[0].ConnectionString;
}
else
{
// try "MasterMSAccess", then empty, then firstone
if (System.Configuration.ConfigurationManager.ConnectionStrings["MasterMSAccess"] != null)
{
return System.Configuration.ConfigurationManager.ConnectionStrings["MasterMSAccess"].ConnectionString;
}
else if (System.Configuration.ConfigurationManager.ConnectionStrings[""] != null)
{
return System.Configuration.ConfigurationManager.ConnectionStrings[""].ConnectionString;
}
else
{
return System.Configuration.ConfigurationManager.ConnectionStrings[0].ConnectionString;
}
}
}
Exception: Operation must be an updatable query when you use an local Access File (.mdb)
Latest Posts
Popular Posts
-
I am *very* keen on automating tests, so I was looking into unit testing a WCF service. If I say "unit test", I mean a fast ,...
-
It's easy I thought, just select the Property of the EntityType and set the Default Value in the Properties window to: DateTime.Now ...
-
*Updated* 26. September 2010: Updated with comments from Adam Cogan *Updated* 27. September 2010: Updated the comparison between anonymo...
No comments:
Post a Comment