C# SQLite database connection WPF Crash - c#

Hi All hopefully someone can help me.
I have written a small WPF app which reads the password of a SQL database and shows it on screen for the user. It works fine on the SQL DB but we have changed to use SQLite and while it works fine on my machine (on which I hav written the program) but when I give the .exe file to a user the program will crash on them, as soon as they click a button to OpenFileDiaglog() (this is so the user can select the database to retrive the password)
After some trial and error (of commenting out parts of the code) it would seem to crash when it hits this line.
SQLiteConnection Dbcon = new SQLiteConnection("Data Source= " + Myfile);
but in the event viewer on the machine i am trying to run the program on the error is
Description: The process was terminated due to an unhandled exception
Exception info: System.IO.FileNotFoundException
I have tried to use the .exe file on a few different machines (vista, xp, win 7) all of which have the .net framework 4.0 installed on them.
Like I say all works perfrect on my machine only when it is moved does the error come up.
Any help would be greatly appricated

Because yu must adjust your path of your database on user machine, you have false path on your DataSource when you deploy
Data Source= Path of your databse
I suggest you this code
"Data Source=" + System.IO.Path.Combine(System.IO.Path. GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), YourFile)

Same problem but this didn't fix it for me. The problem for me was my main app was in .net 4 and the sql lite dll is .net 2 so add useLegacyV2RuntimeActivationPolicy="true" as an attribute to the startup tag in app.config.

Related

Error in accessing local db after deploying my application in different pc

I have a C# application which accesses a local auto-named database like DB_Users.mdf to pull out user connection details.
My connection string is:
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB_Users.mdf;Integrated Security=True
When I deploy this application on a laptop, I get an error like this
The database"C:\ProgramFiles(x86)\ISTL\PCArchieSetup|DB_USEr.MDF" can't be opened because itis version 852 ,the Server support version 782 and earlier.Couldn't open new database "C:\programfiles\IstL\PcArchie\DB_users.mdf"Create database is aborted.An attempt to attach an auto-named database for file "C:\programfiles\IstL\PcArchie\DB_users.mdf" failed. A database with the same name exist or specific file cannot be opened on UNC share
Initially, I thought this VS version problem. So I updated to VS community 2015. But still getting the same error. I suspect the file location it's trying to access is the problem. But don't know how to resolve it. Can you share your thoughts on this? Thanks in advance for your help.

how to read places.sqlite of firefox using c# application

Hi I am trying to get all history url of mozilla firefox. To do that I am accessing places.sqlite file inside %appdata%mozilla/firefox/profile/*.default folder. I am using system.data.sqlite dll in my code and tried x64 and x86 both of the solution. As I am trying to connect the database it is showing me an exception that the file is encrypted or not a database file.
To cross check this exception I've installed a dbmanager for sqlite and opened it. This is showing me all the data that I want to show. But I am not able to get the same data using c# application. Please Help me to get this thing resolved.
SQLiteConnection sqlite_connection = new SQLiteConnection("Data Source=" + dbPath + ";Version=3;New=True;Compress=True;Integrated Security=SSPI;");
SQLiteCommand sqlite_command = sqlite_connection.CreateCommand();
sqlite_connection.Open();// exception occurs here

Building a C# WinForms application with a local Db

I am trying to build my first .exe from a c# winforms project. I am using the Flexera Installing Shield. So far I can build and install it and it runs successfully on the same machine where I am developing. In this project I am using a local db. I can also install it on another machine, but as soon as I`m trying to access the Db via a button it complains. I think it has something to do with the connection string. At least it complains at the line where I am trying to access the Db with:
Error 26 - Error Locating Server/Instance Specified
Here is my obviously wrong connection string:
string connectionString = #"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf"";Integrated Security=True";
Thank you for any help or hint in advance!
Instead of using an absolute path for your connection string, use
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\LocalDbVisTest.mdf;Integrated Security=True
The reason your program cannot find the database is because it is looking in
C:\Users\idiot\Documents\Visual Studio 2013\Projects\Vis\Vis\LocalDbVisTest.mdf
Which, presumably, doesn't exist on your client's machine.
You can manually set your DataDirectory by using AppDomain.CurrentDomain.SetData("DataDirectory", path). You can get the path of your executable by using AppDomain.CurrentDomain.BaseDirectory

WinForms Stopped Working Due to "Prblm Event Name CLR20r3

i created a program in c# and used SQL server 2008 as database and installshield for program .exe package
everything works fine i mean program can be installed normally and there is no error in database or in setup
but when i try to open program it gives the following error(program signature) which i took screenshot of error
i use dotNetBar.dll in my project and its included in setup folder
i changed path of installation and database folder but still the same error
Error screenshot part 1:
Error screenshot part 2:
please help.
The error is the FileNotFoundException, your program is trying to open a file that's not there and you're not handling it in the code.
Have you copied everything?

Connection to SQL Server is failing from executable

I have a windows Application written at C Sharp, which is updating data store in SQL server 2008. When I am running application from .Net, I have no issues. I compiled application and install on the same laptop. When I run exe file I am getting the following error: "System.Data.SqlException (0x80131904): A network-related or instance-specific error occured while-establishing a connection to SQL Server. The server was not found or was not accessible".
Why I can connect to SQL server from MS Visual Studio, and not able to make connection to SQL from executable file (same laptop) ? Thank you.
Make sure the config file where your SQL connection string should be stored is next to the exe file when you install your application.
Please ensure that you have a file called "projectname.exe.config" right next to your exe. If so, then please ensure that you have the SQL connection string in this config file. If so, the please ensure that it is the correct connection string. Also, please ensure that the user account specified in the connection string has access to the DB. If you are using windows authentication (SSPI) then please ensure the your windows account has access to the DB.
NOTE: the config file name MUST be "exeName.exe.config". The exeName is usually the project name. Just in case you have changed the exe name from the default.
Hope this helps.

Categories