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)
Application.Exit vs. Environment.Exit
I looked over my sources and saw that i used Application.Exit and sometimes Environment.Exit...
Without ever knowing, when exactly to use the right procedure!
This article gave me clearness
Application.Exit vs. Environment.Exit
Msdn Help
Application.Exit
Environment.Exit
Essence of the blog post!
if (System.Windows.Forms.Application.MessageLoop) { // Use this since we are a WinForms app System.Windows.Forms.Application.Exit(); } else { // Use this since we are a console app System.Environment.Exit(1); }Good example - Code determines in which context used, Console, Winforms, Class Library, and calls right method
TIP: The symbol file im.pdb does not match the module
If you encounter
"The symbol file pdb does not match the module"
Try to look in
Debug -> Windows -> Modules
Ctrl-D, M
there you can see where vs2008 tries to load the .pdb file.
SOLUTION
Rebuild your dll in DebugMode and deploy it there!
The symbol file im.pdb does not match the module - MSDN Forums
DataGridView daily problems...
i have a DataGridview with some ComboBox cells in there.
each row should have a different list of items to select the value from.
you can set the bindingsource on Enter and reset the bindingsource to the list with all items on EndEdit...
in dataGridView CellEnter
if (e.ColumnIndex == CELLINDEXWhereComboBoxIs)
{
//Set DataSource of cell if comboBoxCell
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dataGridView[e.ColumnIndex, e.RowIndex];
cell.DataSource = bindingSourceFiltered;
}
in dataGridView CellEndEdit
if (e.ColumnIndex == CELLINDEXWhereComboBoxIs)
{
//set DataSource to BindingSource with all items
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dataGridView[e.ColumnIndex, e.RowIndex];
cell.DataSource = bindingSourceAll;
}
ps:
you can add filters to the bindingsource!
but only if the underlying list supports filtering!!
Labels: databinding, winforms
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...