I am REALLY new to Eclipse plugin developement, so maybe my question sounds dumb, but I've been googling for hours...
Whats the way to load an SQLite db into my Eclipse plugin?
First I created a standalone Java application, it loaded, and processed the database file just file, but when I added the code (well copied the files to the new project) it says:
java.sql.SQLException: no such table: measurement
The db file is in the projects root dir.
I thought this issue is caused becouse the applicaiton cannot find the database file, so I changed the filename from test.db to asdftest.db, and I got the same error, so the problem was this indeed.
Thanks!
Here is the code:
public List<Coord> generateModel() {
try {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager
.getConnection("jdbc:sqlite:test.db");
Statement stat = conn.createStatement();
ResultSet rs = stat
.executeQuery("select * from measurement where has_gps = 'TRUE';");
LinkedList<Coord> nodes = new LinkedList<Coord>();
while (rs.next()) {
nodes.add(new Coord(rs.getString("_id"), rs.getString("lat"),
rs.getString("lon")));
}
rs.close();
conn.close();
return nodes;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Related
I'm trying to write a program that will restore many databases, query them using LINQ and then write recieved data to my database.
The first problem I've encountered is that I can't restore any database programatically.
The error says something like this:
"File 'xxx' cannot be restored to 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\xxx.mdf'. Use WITH MOVE to identify a valid location for the file."
I've checked and that's indeed a problem. I haven't got this folder (\MSSQL11.SQLEXPRESS). How to resolve this?
My code for restoring:
private void RestoreDB(string destPath, string dbName, string fileName)
{
var myServer = new Server(#"LOCALHOST");
var res = new Restore();
res.Database = dbName;
res.Action = RestoreActionType.Database;
res.Devices.AddDevice(destPath, DeviceType.File);
res.PercentCompleteNotification = 10;
res.ReplaceDatabase = true;
try
{
res.SqlRestore(myServer);
}
catch (Exception e)
{
Console.WriteLine($"{dbName} couldn't be restored");
return;
}
}
The thing is, I've recently migrated from once PC to another. It worked before but I recall that I've had some problems with SQL before as well. I've read something about this error but I need explanation step by step how to deal with it.
I have a program that works correctly on my computer in Debug mode.
When my program start he create a Sqlite data base file if not exists.
This is ok on my computer.
I create a setup version for production version. The program setup is ok.
But when I start the program (.exe) my db file is not created.
This is the connection string I used :
static string dbDirectopry = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
static string dbName = "MySqliteDb.db";
static string Connexion = Path.Combine(dbDirectopry, #"MySociety\MyApplication\" + dbName);
Hi thanks for your help,
this is the code that create db.
public static void CreateDb(string path)
{
SqLiteHelper sqlite = new SqLiteHelper(path);
try
{
User.CreateTable();
}
catch (Exception e)
{
throw e;
}
}
Normaly if the file doesn't exists he is automaticaly created.
If I try my application in Debug mode with Visual Studio my db is created and I can write into.
But when I deploy my application it doesn't work anymore.
My problem is is there any special directory (for windows) to create de db file?
Hello I am having problems with testing if my embedded datbase exists.
I created a database like follows:
try {
SQLiteConnection.CreateFile("AttendanceDatabase.sqlite");
} catch (SQLiteException ex) {
}
And then I insert tables and data into the tables, everything works fine. When im saving data to the database im using the the connection string as follows:
conn = new SQLiteConnection("Data Source=AttendanceDatabase.sqlite;Version=3;");
Now my problem is everytime I run my program it creates the database over, and I would like to know how to test if the database exists it should not create the database over again.
I see the recomended way to do it is using the next statement:
if (File.Exists())
{
}
and I have tried using it as follows:
if (File.Exists("Data Source=AttendanceDatabase.sqlite;Version=3;")){
MessageBox.Show("File Exists");
}
but it does not want to go into the if brackets and display "File Exists".
So I would like to know what my path should be for my embedded database, that is if thats where my problem lies?
Thanx in advance!
I don't have a ton of context but if you update your check:
var basePath = "C:/<path to file>/";
if (File.Exists(basePath + "AttendanceDatabase.sqlite")){
MessageBox.Show("File Exists");
}
You might have more luck. If you give me more context to how you are running this I can help you with using services to lookup the file path. You can look it up based on assembles, approot, etc.
I am trying to create a Sqlite database using Monotouch 3.0.3.4. Everything works fine on the iPhone simulator, but I get the following error on the test iPhone:
DataLayer.CreateDatabase Exception: System.UnauthorizedAccessException: Access to the path "/private/var/mobile/Applications/4B4944BB-EC37-4B0C-980C-1A9B60DACB44/TestApp.app/myDatabase.db3" is denied.
Here is the code I am using:
// creates database and tables if they do not exist.
public void CreateDatabase ()
{
string sql = string.Empty;
string dbFileName = "myDatabase.db3";
try {
if (!File.Exists (dbFileName)) {
// create database
SqliteConnection.CreateFile (dbFileName); //This is where the error occurs
Console.WriteLine ("CreateDatabase: Database created.");
...
}
catch (Exception ex) {
Console.WriteLine ("CreateDatabase Exception: " + ex.ToString ());
}
...
I have also tried specifing the personal folder, but that has no effect. What do I need to do to make sure permissions are correct?
Thanks!
Monotouch 3.0.3.4
That's likely MonoDevelop 3.0.3.4. See About MonoDevelop to get the MonoTouch version.
"/private/var/mobile/Applications/4B4944BB-EC37-4B0C-980C-1A9B60DACB44/TestApp.app/myDatabase.db3"
On devices the applications are signed, so their content can't change (without breaking the signature). As such you're not allowed to change things in the .app directory.
You should create (or copy) the database in the Documents directory and then open the database as read-write.
See the linked article for more details.
I'm currently working with Integration Services (SSIS) to load a big amount of XML files into a SQL server database. Each XML file content needs to be dispatched in several tables. I have at least 10000 xml files to load using the process. Everything works fine till 6000 files are loaded. After 6000 treatment, I always got an OutOfMemoryException from my first dataflow task, the first in the process.
In this script component, I just check if a value from a XML file is already present in a specific database table. If it is present, I return the matched ID, otherwise, I add a new record. To achieve it, I use a Lookup component. I use it with No cache option, for memory matter. Then in case of matching, I process the return ID in a script component. Like I said, everything works fine until more or less 6000 files are processed. After I got :
Description : System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.HandleUserException(Exception e)
at Microsoft.SqlServer.Dts.Pipeline.ScriptComponentHost.PreExecute()
at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostPreExecute(IDTSManagedComponentWrapper100 wrapper)
Do you have some suggestions or some ressources which deal with performance and memory issue in SSIS ? Do you encountered similar problem ? DO you have an idea from where this memory problem could come from?
Thanks :)
EDIT:
Here is the code to check an XML against an XSD file. Can you see any memory leak?
public void Main()
{
try
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add("", Dts.Variables["XSDFilePath"].Value.ToString());
settings.ValidationType = ValidationType.Schema;
using (XmlReader reader = XmlReader.Create(Dts.Variables["XMLFilePath"].Value.ToString(), settings))
{
XmlDocument document = new XmlDocument();
document.Load(reader);
ValidationEventHandler eventHandler = new ValidationEventHandler(XMLValidationHandler);
document.Validate(eventHandler);
}
if (ValidationResult)
{
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
catch (Exception ex)
{
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
private void XMLValidationHandler(object sender, ValidationEventArgs e)
{
switch (e.Severity)
{
case XmlSeverityType.Error:
Console.WriteLine("Warning {0}", e.Message);
ValidationResult = false;
break;
case XmlSeverityType.Warning:
Console.WriteLine("Warning {0}", e.Message);
break;
}
}
Don't use the XMLDocument Object, It will load the entire document into memory and is likely the cause of your memory problem. Try instead to use the XmlValidatingReader
http://msdn.microsoft.com/en-us/library/system.xml.xmlvalidatingreader.aspx
It should provide a more efficient use of memory.
Refer to the 'answers' in this.,
http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/4d90afc8-0a1c-418f-9e3a-0b766f581b2c/