Cannot access SQL Server CE DB after installation - c#

I have created a Winforms app that writes all data to a SQL Server CE database. I am able to successfully install the app but when I try to read or write data, it tells me that it cannot open the connection. This only happens on PC's other than the one I created the program on. Nothing is hardcoded.
Does anyone have any suggestions?
Thank you

Windows will fight you with permission issues for locating the database in the Program Files directory. It doesn't belong there.
Consider moving the database to your own folder in this root folder:
Environment.SpecialFolder.ApplicationData
Obviously, the connection string needs to reflect that folder path.

Related

C# database error while running application on Clients Computer

I have created a project and so far in that project I am using localdb to create a database, reading a CSV file from a shared drive.
I have copied a .exe file from bin\Debug and copied that onto the client's computer. I am getting the following error, can someone please help:
[
Is it because my client does not have sqlserver or localdb installed?
I need to create an application without requiring any setup to be installed at client machine.
Please let me know if it is possible. Thanks

Transferring winforms app with local db to other computers

I have built an app with winforms application and added a local database to my project using based-data source.
on the app load event the app connects to the database and loads its components accordingly.
everything works fine on my pc but the problem is when I am transferring the app to other computers. I am getting an error every time the app tries to connect to the database (local Database Run time error occurred).
Tried to install SQL Express localdb 12 on the other computers and checked that the service: SQL Server VSS Writer is running but still getting the same error.
Note: the database.mdf file exists in the same location on all the computers.
SQL Error:
How can I fix it?
I suggest not to hard-code connection string in code. Move connection string in configuration file and access from their and rebuild your application. Now when you move your project to other computer, you move configuration file which is generated by build as well. On new computer, open DB and freshly copy your connection string and replace it in your configuration file and then run your application. Hope this will help.

Clickonce deployment with SQL Server CE

I manage to finish my project and publish it for deployment on other machines. My C# WPF application have SQL Server CE as its backend database. I wanted the database to be able to work in other machine that have no SQL Server CE installed. I publish it using clickonce, the publish was successful. However when I run it on other machines, and tries to open the database there is an error prompt that said 'database file cannot be found. Check the path to the database [Data Source=D:db.sdf]. I followed the tutorials on clickonce by mdsn, Microsoft and by other people, the result is always the same. The local database cannot be detected.
D:db.sdf is not created by ClickOnce, you must have changed something. ClickOnce by default installs data that is included in a project to a directory in the app folder, and sets the DataDirectory app domain value to the path to this directory. In your application you should use something like
SqlConnection("Data Source=|DataDirectory|db.sdf;...")
Note that DataDirectory may not be writable by users. If you want users to save data you should copy |DataDirectory|db.sdf to some place writable like
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

.Net Application Installation 2012 with database

I have built a Windows Forms application using Visual Studio 2012 and MSSQL 2008. I need to deploy this project using InstallShield Limited Edition.
While running this application on my pc, it does nto work well when I use the following connection string or .//SQLEXPRESS.
I need the installer to find the exe file of the application on other uer's pc with the database file. Where do I need to put my database files in the deployment files folder? What should my connection string be?
i use .//SQLEXPRESS it doesnt work as well
DO NOT use .//SQLEXPRESS as datasource name in the connection string.
Recommended way is to menthion Instance Name if your application is to be deployed in different environments(especially OS). I ran into trouble when I had the Datasource as .dot which worked in Win 7 not in WinXP. Either one of the following approach works fine.
(local)\SqlInstanceName
(ComputerName)\SqlInstanceName Ex: CD-SJHONES\SQLINSTNACE
In certain cases i had to include the computer name, So during the application deployment i get the computer name and update the connection string accordingly.
where i need to put my database files in deployment files and folder
and what should be my connection string
Connection string
I have already answered connection string releated question above.
Database files
What do you mean by database file. how database is created in the client machine ? do you create a database during application deployment or users manually create it with script ? There is nothing to worry about the database fine as long as your application have right connection string to point to your database.
Application files and folders
Again this doesn't really matter where application files and folders resides in the client machine. It's upto the users to decide where he/she likes to install the application.
You cannot install from backup. Also in your scenario, you should force end user t install Sql Express, what If it has already installed. So You need considering , scripting of entire database. You can create another exe / look for option in Installshield to execute that Script incase the database server is found else, force user to download the Sql Sever Express or Embedd it into setup and execute the script over there. But that will make your Setup Size more than 100's of MB.

Setup SQL Server for database made in c#

I have a problem, I made a nice application in C# with a SQL database, now I wanted to install that application on another pc but it doesn't connect to database file. Is there a nice way that I can install that database and connect to it with only changing connection string in my program. Is there any way that I can access the database through network? I tried to find some tutorial but without luck..
I would suggest you to append the database file (which ever it is) to your project. So it will be located inside the project`s folder.
But before Publishing the application, change the connection string, instead of a full path use |DataDirectory| . This is an example:
//from
#"....Database=C:\MyProject\MyDataBase.mdf;...";
//change to to:
#"....Database=|DataDirectory|\MyDataBase.mdf;...";
This way you will not have issues with connection string.
But dont forget to ADD the database file to your project (incuse it in it).
You need SQL Server Express to connect to database files. You have this installed automatically with visual studio, but another computer may not have it. Make sure that another computer has SQL server installed.

Categories

Resources