I have a Sqlite database that I include with my MonoTouch app. It has worked fine for me so far, but now I want to open it in read-only mode rather than read-write.
So I have changed the connection string to include 'Read Only=True', but when I call Open(), I get the following error:
Library used incorrectly (at Mono.Data.Sqlite3.Open)
If I dig into the exception it shows
_errorCode = Misuse
and that's about all the info it gives.
Here's the code:
var _conn = new SqliteConnection("Data Source=db/sampleDb;Read Only=True");
_conn.Open ();
You found a bug in Mono.Data.Sqlite.dll.
The Create flag is appended (by default) before the ReadOnly flag is parsed and set. The resulting flag is invalid and sqlite reports an error.
I will fix this for future releases (of Mono and MonoTouch...). If this blocks you then please open a bug report on http://bugzilla.xamarin.com and I'll attach a fixed assembly (with instructions to replace the existing one) to the bug report.
This worked for me (aspnet core):
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ReadOnly");
Have you tried?:
var _conn = new SqliteConnection("Data Source=db/sampleDb;mode=ro");
Your code is correct, I just tried it (not using MonoTouch) and it worked for me.
Do you have the latest version of System.Data.SQLite.dll?
If yes, then maybe it's a problem related to MonoTouch.
Related
My program hangs when it gets values using Entity Framework. Here is my simple code:
LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // it hangs here
It's not an async method. There are solutions about async but I didn't find any solution to fix my problem.
It doesn't respond, it's waiting forever. All my code was running until 2 days ago. I didn't type or do anything and this bug happened (short video is here)
I have tried these things so far:
I removed Entity Framework model from my solution and I added it again
I created a new program and I used exactly same codes and model (it worked):
LearningEnglishEntities1 db = new LearningEnglishEntities1();
List<tb_Words> sample = db.tb_Words.ToList(); // It worked
I cleaned my solution
I typed this code:
var query = from item in db.tb_Words select item; // It hangs the same way
I checked this code is not run by another thread:
bool query0 = this.InvokeRequired;
if (!query0)
{
LearningEnglishEntities db2 = new LearningEnglishEntities();
List<tb_Words> searchedItems = db2.tb_Words.ToList(); // It still hangs
}
I changed my Entity Framework 6.0x version to 5.0x but it didn't
work.
I completely copied all files and pasted to a new project. It ran but it didn't work
I restarted Microsoft Distributed Transaction Coordinator Service and checked startup type is Automatically. It didn't work.
Strangely, it works on other projects but it hangs on this project. I haven't found any solution to fix this bug. Do you think what should i do?
Also My Connection String is :
<connectionStrings><add name="LearningEnglishEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=DESKTOP-REKGVD4\SQLEXPRESS;initial catalog=LearningEnglish;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
Thank you
After all things, I was able to find a solution but I don't know the reason. Using Entity Framework Code First solved my problem. It is not good for my project but i have to use it.
I am creating an application which uses access file from shared network.The application works fine when the access file is placed local.But when I placed it in shared path and trying to connect.It is throwing an exception."An OLE DB Provider was not specified in the ConnectionString. 'Provider=SQLOLEDB
Here is my code:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\server\\MyFirstProject\\SampleDB2.accdb";
using (OleDbConnection con = new OleDbConnection(connectionString))
{
string command = "INSERT INTO emp_status(emp_id,hours,feeded_on,comments)";
command += "VALUES(#emp_id,#hours,#feeded_on,#comments)";
Could anyone help me how to resolve this issue and Am I missing something?
I am using OLEB as a datasourse and Access 2013
Any Suggestions or explanations would definitely helps me.
Thanks in advance!!
You need to escape the leading double slash as well...
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\\\server\\MyFirstProject\\SampleDB2.accdb";
I haven't got anything to check this on here, but I'm fairly sure this is your answer. Also, watch out for reserved words, E.g. "hours" might be one in which case it should be [hours].
Also, you haven't specifically included adding the parameter values in your question. I assume you are doing it but if not then see my coding example here...
VB 2010 error (INSERT INTO) syntax error
I am trying to create a graph with C# and the WPF chartingToolkit, I have the following code:
LineSeries lineSeries1 = new LineSeries();
lineSeries1.Title = region;
lineSeries1.DependentValuePath = "Value";
lineSeries1.IndependentValuePath = "Key";
lineSeries1.ItemsSource = points;
this.Graph.Series.Add(lineSeries1);
where points is a Dictionary<string, int> created in earlier code. This code compiles fine and runs fine until it reaches the line LineSeries lineSeries1 = new LineSeries();. Upon reaching this line it throws a Source Not Found: LineSeries.cs not found exception. I have tried putting it as System.Windows.Controls.DataVisualization.Charting.LineSeries lineseries1 = new System.Windows.Controls.DataVisualization.Charting.LineSeries(); but that failed to fix the issue. Everywhere I look for examples of how to do this it is written exactly how I have it.
EDIT:
It works perfectly without the debugger. The problem only exists with it.
The debugger was looking for a source file but was not able to find it. This will have been either because you don't have it available or because the version of the source you have does not exactly match the version which was compiled into your library.
If the latter is the case, you can work around it by going to Tools -> Options -> Debugging and unchecking the "Require source files to exactly match the original version" option.
I have a C# .NET WinForms application that uses Crystal Reports.
Crystal reports run fine on both x32 and x64 systems with the exception of reports containing subreports. Any report containing a subreport fails with the wonderful: "Log on failed" at ...VerifyDatabase() but only on x64 systems.
I have seen and fixed this problem in the past by unchecking Verify Database on every print, making sure the no data is being saved with the report and ensuring the correct driver and connection methods are being used in the designer. This problem is not going away and seems to only be affecting reports with subreports.
All projects in the solution are set to build to x32.
The x64 systems have the CR 32bit runtime installed.
The SQL Native Client is also installed.
I have tried many different combinations of report preparations steps like not verifying the database, not refreshing the report, verifying and not refreshing, refreshing and not verifying... it goes on and on.
Here is the current preparation method being used:
private T GetReport<T>() where T: ReportDocument, new()
{
var report = new T();
var connectionStringBuilder
= new SqlConnectionStringBuilder(this.ConnectionString);
var connectionInfo = new ConnectionInfo
{
DatabaseName = connectionStringBuilder.InitialCatalog,
UserID = connectionStringBuilder.UserID,
Password = connectionStringBuilder.Password,
ServerName = connectionStringBuilder.DataSource
};
Action<ReportDocument, bool, bool> setConnection = (document, verify, refresh) =>
{
document.DataSourceConnections.Clear();
document.DataSourceConnections[0].SetConnection(
connectionStringBuilder.DataSource,
connectionStringBuilder.InitialCatalog,
connectionStringBuilder.UserID,
connectionStringBuilder.Password
);
document.DataSourceConnections[0].IntegratedSecurity = false;
/*
foreach (Table table in document.Database.Tables)
{
var tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);
}
* */
//document.SetDatabaseLogon(connectionInfo.UserID, connectionInfo.Password, connectionInfo.ServerName, connectionInfo.DatabaseName);
if (verify)
document.VerifyDatabase();
if (refresh)
document.Refresh();
};
for (var index = 0; index < report.Subreports.Count; index++)
{
var subreportName = report.Subreports[index].Name;
var subreport = report.OpenSubreport(subreportName);
setConnection(subreport, false, false);
}
setConnection(report, true, true);
return report;
}
SOLVED: I have gotten the report to work. I am not sure what part of this solution actually solved the problem but these are the steps I took.
I checked the data source per aMazing's suggestion below. (It was already OLE DB)
I removed all referenced to Crystal Reports in all projects in the solution.
I re-added the Crystal Reports references and made sure all the references were the same version and made sure all references were set to 'Specific Version' = True.
I set 'Copy Local' to True on the CR references on one project in the solution.
I changed the call to the **setConnection** to not verify.
I un-commented foreach table.ApplyLogOnInfo(tableLogOnInfo) section.
I'm not sure why it works now but it does. The table.ApplyLogOnInfo was un-commented in many of the permutations I tried earlier. Maybe I never hit this specific combination... but I don't care at this point.
SOLVED: I have gotten the report to work. I am not sure what part of this solution actually solved the problem but these are the steps I took.
I checked the data source per aMazing's suggestion below. (It was already OLE DB)
I removed all referenced to Crystal Reports in all projects in the solution.
I re-added the Crystal Reports references and made sure all the references were the same version and made sure all references were set to 'Specific Version' = True.
I set 'Copy Local' to True on the CR references on one project in the solution.
I changed the call to the **setConnection** to not verify.
I un-commented foreach table.ApplyLogOnInfo(tableLogOnInfo) section.
I'm not sure why it works now but it does. The table.ApplyLogOnInfo was un-commented in many of the permutations I tried earlier. Maybe I never hit this specific combination... but I don't care at this point.
Because I couldnt add a comment, this was the only way I could reply.
What SQL server are you using? I had something similar before.
Check the following on both report and sub report:
1) Right Click Datasource Properties
2) Select Set Datasource Location
3) On the connetion that the report is using, click expand Properties
4) Confirm that the Database Type = OLE DB (ADO) and Provider is SQLOLEDB.
That fixed my problem. I had set it to SQLNative Client before which was failing.
Hope it helps.
Thanks
Check if you have an Access database or any other 32 bit datasource in any of the subreports.
I had this same problem recently. I found the cause to be not setting the datasource, which in my case was due to an incorrect if statement, meaning the following line was not running:
repdoc.Subreports["SubReportName.rpt"].SetDataSource((DataTable)MyDataTable);
Hope this is of use.
I need to create an access (mdb) database without using the ADOX interop assembly.
How can this be done?
Before I throw away this code, it might as well live on stackoverflow
Something along these lines seems to do the trick:
if (!File.Exists(DB_FILENAME))
{
var cnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DB_FILENAME;
// Use a late bound COM object to create a new catalog. This is so we avoid an interop assembly.
var catType = Type.GetTypeFromProgID("ADOX.Catalog");
object o = Activator.CreateInstance(catType);
catType.InvokeMember("Create", BindingFlags.InvokeMethod, null, o, new object[] {cnnStr});
OleDbConnection cnn = new OleDbConnection(cnnStr);
cnn.Open();
var cmd = cnn.CreateCommand();
cmd.CommandText = "CREATE TABLE VideoPosition (filename TEXT , pos LONG)";
cmd.ExecuteNonQuery();
}
This code illustrates that you can access the database using OleDbConnection once its created with the ADOX.Catalog COM component.
I've done the same as Autsin, create an Access db then included it into my project as a managed resource. Once there, it is included in the compiled code and you can copy it to hard disk as many times as you want. Empty databases are relatively small too, so there isn't much overhead.
The added bonus is the ability to set up the database if you know how it will be used or what tables will be added every time, you can reduce the amount of coding and slow database queries.
You don't need Jet(major headache) installed, if you use this connection string in .net 3.5
Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\myFolder\myAccess2007file.accdb;Persist
Security Info=False;
This should work on access 2007 and below
Interesting question -- I've never thought to create one on the fly like this. I've always included my baseline database as a resource in the project and made a copy when I needed a new one.
ACE is not in any framework (yet. ie not in 1, 2, 3.5, 4, 4.5)
It's also not part of Windows Update.
JET4 is in Framework2 and above.
If you're working with Access/MDB files etc then do not assume ACE is present.