Clickonce deployment with SQL Server CE - c#

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)

Related

DO I need to setup sql server in a computer to run c# desktop application file made in vs 10?

I have a desktop application made in vs 10 with sql server 8. I have added the mdf file in app_code folder of project and the app.config is changed accordingly.The application is published and is availabel as setup file(.exe).If i want to install it in another pc, do i need to install the sql server in that pc?
The short answer is Yes
The idea is database needs a server to host it and an engine to run it
mdf file has no value without sql serve and access files has nothing to do if you don't have MS Access installed, etc.
But this does not mean db server must be installed on the client machine that has the application. as it can be on another machine or on the cloud (i.e. hosted on the internet)
As long as your application is connecting to that machine/server

Cannot access SQL Server CE DB after installation

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.

.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.

Deploying C# application with SQL database

I have developed a C# application with SQL database, now i want to package it with the database and deploy it on some other machine which does have sql installed. How should i go with it.
What should be the connectionstring for the project, currently i am using "initialcatalog".
Pls Help
I am not sure, if I understand the question well.
If this is a C# class library only, you can get the dll and deploy in the required application.
If this is a web application, you can either create a web deployment package or publish the site.
For SQL migration, you can used the database publishing wizard from microsoft.
http://www.microsoft.com/en-in/download/details.aspx?id=5498
I hope my answers helped you.
Make .bak file of your SQL database.
Publish c#.NET application.
In the folders where you programmed this application, you will find published setup of your application.
Complete wizard in that publish setup folder.
upload database backup file(.bak) where you want to install application.
In this way you can deploy your application.
there are some install maker tools like install shield, which you can make a setup for your application,
About your connection string if your sql server is on your local computer you should set the "DataSource = . "
somthing like this : "Data Source=.;Initial Catalog=yourDBName;User ID=sa;Password=1"
the dot means local computer.
to create your data base on the target computer you can right click on your database and select task\generateScript and follow the wizard to make your database script the run that script on the target computer.
It's a common practice to include mdf or sdf file directly in solution (at least that's how are a lot of MS examples like Northwind/AdventureWorks are done). So you need to detach your db and then simply reattach it to other db server. You can read more here http://goo.gl/0FV1N
You can create a set of SQL Scripts to build the database via T-SQL or you could create a script to attach a new database to the server using the MDF/LDF files you include with your project.
Examples:
C# use script to create database
http://support.microsoft.com/kb/307283
Regardless of how you do it, you'll first need to establish a connection to the SQL Server with rights to create a new database. You might want to prompt for these values during install or on the first launch of your program.

Database '...\DATABASE.MDF' cannot be upgraded because it is read-only or has read-only files

I wanna install an ASP.NET application on WIN XP SP3,
Thus I've installed IIS 5.1 , .Net Framework 3.5 SP1 and MSSQL 2008 R2 on my WinXP SP3.
Then, I copied my application folder to C:\Inetpub\wwwroot\
Next, I've created an application from my folder in IIS Manager and I set the permissions as the following image :
As you can see, I can't write and even read from the database and whenever I wanna write into the database I receive the above exception.
What's the wrong with it ?
P.S:
I'm using Win XP on VMware Workstation 7.1
The application is running in Win Vista x86 and Win7 x64 without any problems.
The application was written with .Net Framework 3.5 SP1
You must edit permissions, allowing "Network Service" to edit the MDF file.
Did you check your database file's property (readonly attribute), and ACL security permissions (permissions that are defined on the file level - not in the IIS management console) ?
I've found the solution.
I disabled the Windows Firewall and shared the folder with `Allow Users to change my files" , and now I can write and read from the database easily :-)
This was weird. It turned out part of my application was referencing one aspnetdb file in Sql Server and the other was trying to reference one locally created in the application.
My connection string was for this :
<add name="ApplicationServices"
connectionString="Data Source=localhost; Initial Catalog=aspnetdb; Integrated Security=True" providerName="System.Data.SqlClient" />
But the error was this
There was a failure using the default 'ProfileProvider'. Please make
sure it is configured correctly. Database
'C:\WEBSITES\XXXX.SILVERLIGHT\ADMIN\APP_DATA\ASPNETDB.MDF'
cannot be upgraded because it is read-only, has read-only files or the
user does not have permissions to modify some of the files. Make the
database or files writeable, and rerun recovery.
It took me a while to notice that this was under my application root, and not the Sql Server version that the main part of my application uses.
In my case I just renamed the locally created aspnetdb files and when I reran the pplication it just recreated them at their default sizes (10240kb and 504kb).
I'm not quite sure how this is happening, but i my case this was a sufficient fix.
I think maybe I wasn't using the profile provider explicitly so it was using default settings. The rest of the application was using the correct connection string.
You add Users group into the sercurity tab with Full Control

Categories

Resources