I used the PostBuildevnt script to launch the application form link
http://blogs.msdn.com/b/astebner/archive/2006/08/12/696833.aspx?wa=wsignin1.0&CommentPosted=true
and launching the app successfully.I am using the sqllite for app.
I added the DB file in Application Folder/DataBase and using the following code to open the Db file.
string ConnectionString = "data source=" + Path.GetFullPath(".") + "\\DataBase\\CATTDB.db";
If i launch the app from the installation wizard,it is not connecting to db file.it is throwing the error like "Unable to open the file".
If i launch from the start menu or desktop icon ,it is working fine..
What is the problem here?
please help me..
It could be that your working directoy is different when started from the installer...
What does Path.GetFullPath(".") return in this case (log and/or display the value)?
There is always the issue of permission/rights - depending on your OS (i.e. Windows 7...) and the user your running the app with (i.a. Administrator?) for security reasons you are not allowed to write in the application directory... if you need someplace with read+write you should use http://msdn.microsoft.com/de-de/library/system.windows.forms.application.userappdatapath.aspx
Just check whether the db is in that path -if not copy it there- and use it there...
Other locations could be ApplicationData/CommonApplicationData/LocalApplicationData from http://msdn.microsoft.com/de-de/library/14tx8hby.aspx and http://msdn.microsoft.com/de-de/library/system.environment.specialfolder.aspx
All the files are copying correctly..
I tried with Application.ExecutablePath instead of Path.GetFullPath(".")
it work's great...
Related
I am having a strange problem that I am unable to access files written by my c# application. My app basically does :
var file = "C:\\Users\\Public\\Documents\\something.txt";
List<string> content = new List<string> { "one thing", "two things" };
Console.WriteLine(System.IO.File.Exists(file));
System.IO.File.WriteAllLines(file, content);
Console.WriteLine(System.IO.File.Exists(file));
The first time I run the app, the output is
False
True
Yet I cannot see the written file in Windows Explorer (Windows 10). I get no exceptions attempting to write the file. The second time I run the app, the output is :
True
True
According to my application the file is being written however Windows thinks differently. As a sanity check I spun up a second app that opens a dialog using OpenFileDialog. When I run that, I am able to see my written files! Windows explorer still cannot. Attached is a screenshot of windows explorer and my openfiledialog side by side.
If I go to notepad and browse for the file I cannot see it or manually type in the name.
Its been a long week of work, there must be some dumb explanation...? Help! :-)
Screenshot - windows explorer on left, c# app open dialog on right :
https://imgur.com/a/8ZTDIe6
per #BACON 's suggestion in the comments above I discovered that after disabling the Comodo anti-virus I am able to write and see my files.
I believe the software is running my app or either only allowing IO from my app in some kind of container. I need to figure out how to grant my apps proper permissions through the anti-virus software, but that was the culprit.
I am creating a plugin for AutoCAD which uses an external Database(SQLite).
and on rare occasions i am getting the "table not found" error. Its driving me crazy. I have seen plenty of forums for answers could not find a solution.
it is working on most cases only few instances it throwing this error.
How do I solve this issue.
I am using relative path to the DB and it lies within the Debug/ release folder.
What is the best approach to attach a db to a application (in my case its a .dll not exe)
thanks guys for reply...Sorry I didnt get any email notification...
Here is the information you requested.
I have a seperate class-which handles connections.
here is how i I connect to the DB.
public static SQLiteConnection GetConnection()
{
string conn_string = string.Format("Data Source=./sdf_db1.s3db");
SQLiteConnection conn = new SQLiteConnection(conn_string);
if (!System.IO.File.Exists("./sdf_db1.s3db"))
{
Global.variables.mess_out_exception("Missing Database file", "Error");
}
return conn;
}
Since this is a plugin for AutoCAD Civil3D it resides in the Appdata\autodesk folder to load on start-up. Everything about the app is working great except rarely I get the table not found error..looks like may be the relative path cannot resolve quickly when the application is started.
I have difficulty finding the absolute path if I tried to use "Application.ExecutablePath;" and few other things which I find online..all I get is the location of Acad.exe not the location of the plugin.
How do I get the absolute path of the location of the plugin to get the location of the DB(since the DB and .dll lies in the same folder).
How do I use both absolute and relative path in the connection string (so if the relative path fails the code can try to locate the db using the absolute path).
Any other suggestion would be great. Thanks
I Found the cause for the issue,
When I run the application and close the application correctly (Means after completing all the process) it works fine I dont get any error message...
I get the error only when I close the window of the application in between. Looks like the connection opened for the DB is still busy if I try to run the application.
Get the path of the plugin with
var asmpath = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location );
Why not take an alternate route?
Instead of trying to find your DLL and associated SQLite database, I would recommend that you install them in a specific location. This way you can easily package it with an installer.
You can utilize automatic loading of .NET modules through AutoCAD with registry keys:
http://through-the-interface.typepad.com/through_the_interface/2006/09/automatic_loadi.html
With this, you can simply install your AutoCAD plugins as if they were a normal program, and get AutoCAD to load them for you on launch.
I have a window application which tries to connect a MS Access file which is all ready used by another application.
When I stop that application then I am able to connect with MS Access file.
Otherwise an error occurs as follows:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "AccessDb" returned message "Cannot start your application.The workgroup information file is missing or opened exclusively by another user.
Is there any way which I can open a connection in read only mode.
I have to just read data from that file.
Thanks.
Try adding "Mode= Share Deny None" to the connection string of this application that is locking the DB, so that the connection string looks like
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyFolder\MyDb.mdb;Persist Security Info=False;Jet OLEDB:Database Password=My_Password;Mode= Share Deny None
This connection string should be used by the application that is currently opening the DB in exclusive mode.
I was facing similar problem and it's solved now.
In connection String u might have provided
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\serverName\shareName\folder\myDatabase.mdb;User Id=admin;Password=;
Don't provide Password and instead while sharing file click on advanced sharing and remove administrators users and add everyone with full control.
then run your application
I am having issues connecting to my sqlite database. The file is located in the application's folder. Here is the connection string
string path = "Data Source=MY.db";
I can get it to work if I use the absolute path, but it gives me a "table not found" error if I try to use a relative path. Any ideas?
You are opening up a different -- perhaps a new -- database that does not have said table. (Yes, SQLite will happily create a new database with the default connection settings.)
Make sure the correct database is opened. Remember, relative path is relative to the Current Working Directory, which is likely not that which is expected.
(The working directory is influenced from where, and how, the process is loaded. The working directory for a "Debug" session can be set under Project Settings / Debug / Start Options, for instance.)
Happy coding.
See also:
Make SQLite connection fail if database is missing? (deleted/moved)
Defining a working directory for executing a program (C#) (Shows how to set the current working directory to the directory containing the executing assembly.)
How do I get/set a winforms application's working directory?
Getting path relative to the current working directory?
This happened when you haven't saved the database and its table while using GUI Manager for SQLite .
Two solution;
1) Save your database and its table with CTR+S in GUI Manager
2) Or Simply Just close your GUI manager of SQlite and save all .
Important ! I am using GUI manger for SQLITE (DB Browser for SQLITE) and its all about that.
I've had the same problem for both my windows application (C#) and web application (ASP.net). I usually use SQLite because I found it more easier, especially when I worked with connection strings. But the main obstacle for me was to put a relative path in my code, so I can publish it without worrying about being unable to find the database. I've tried many things(using "|Data Directory|", "~/", "./", ...), and none of them works until I found these solutions. It seems the code is working for me, but wonder if I'm using them right?!
Web Application:
SQLiteConnection sql_con = new SQLiteConnection("Data Source =" + Server.MapPath("~/") + "mydb.db; Version = 3; New = false;);
Windows App:
SQLiteConnection sql_con = new SQLiteConnection("Data Source =" + System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "mydb.db; Version = 3; New = false; Read Only = true");
just replace your .database file into \bin\Debug in project folder, because in your case compiler creates DB file with same name but its totally empty 0bytes
I have a Windows Service that hangs when opening an OLEDB-connection to an Excel-file, like this:
using (var connection = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ fileName + ";Extended Properties=\"Excel 8.0\""))
{
connection.Open();
// start using the connection
}
This code works fine when running as a console application. When I debug the Windows Service with Visual Studio, I can step into the code until I hit the call to connection.Open(). At that point, the thread hangs. No exception is thrown. Visual Studio remains responsive, until I hit the "Break All" or "Stop Debugging" button. At that point, Visual Studio also hangs. When I kill the process, Visual Studio becomes responsive again.
Does anyone know why this happens and how to solve it?
EDIT: fileName is an absolute path; the file was written by the service itself.
After unsuccessfully trying to do this inside the Windows Service, I extracted the business logic into a separate Console Application, and just call that application from within Windows Service. Seems to work fine.
I do not know why this happens, but have you tried to narrow it down by trying to open the file and simply load it into a byte array - to determine whether the issue is with the file system / permissions / etc... rather than OLE DB? If you can open and load the file into a byte array, but OLE DB still hangs, is the CPU pegged which would indicate that there might be something about the file which OLE DB cannot handle?
If you cannot get this to work with OLE DB, have you considered a 3rd party xls / xlsx library like SpreadsheetGear for .NET? You can see live samples here and download a free trial here.
Disclaimer: I own SpreadsheetGear LLC