Cannot deploy application with SQL Server CE database.file - c#

I am trying to deploy a simple windows desktop app using a SQL Server database.sdf file. I have followed the steps in this walkthrough about 10 times and I still am having problems. http://msdn.microsoft.com/en-us/library/bb546200.aspx
In my app.config file my connection string is this:
<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString"
connectionString="Data Source=C:\Users\Eamon\Documents\Visual Studio 2008\Projects\VendorTracker 2.0\VendorTracker 2.0\Database1.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
According to the walkthrough, the windows installer should recognize that I am using a SQL Server CE .sdf file and create a new connection string:
<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString1"
connectionString="Data Source=|DataDirectory|\Database1.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5" />
It does add this connection string to the app.config file. Now I have both connection strings listed in the app.config file. When I deploy the app onto my development computer, it works fine, no problem connecting to the .sdf file.
But when I copy the install folder and everything inside of it to a different "testing" computer I get the following error when I try to run the app:
The path is not valid. Check the directory for the database. [ Path=C:\Users\MyName\Documents\Visual Studio 2008\Projects\VendorTracker 2.0 Database1.sdf].
The app continues to run but there is no data and It will not allow me to save anything to the database.
Why doesn't the .sdf file get deployed with the connection string:
Data Source=|DataDirectory|\Database1.sdf
like it is suppose to? Driving me nuts. I have tried everything. Has anyone successfully used a SQL Server CE .sdf file with a stand alone windows desktop app? I know they are used a lot for mobile devices but that shouldn't make a difference. Please help.
Oceantrain

You must change the connection string manually. Also, consider carefully where you place the file, as not all places are writable

Related

Connect to SQLite .db file served on localhost using http-server (node.js) from my VS C# project?

Initially I developed my project by putting the .db file within the project folder. Now I want to host the database on localhost so I put the db file on a new folder and started a http-server using node.js on localhost:8080. To start the server I used this command on node.js command line C:\Users\Me\aswserver>http-server .
aswserver folder contains only aswDB.db.
On my C# project until now I used the connection string
<connectionStrings> <addname="SQLite"connectionString="DataSource=.\aswDB.db;Version=3;"providerName="System.Data.SQLClient"/>
</connectionStrings>
and included the db file to project(Build Action: Content and Copy to output if newer).
After hosting the db on localhost I tried this connection string
<connectionStrings>
<add name="SQLite" connectionString="Data Source=localhost:8080/aswDB.db;Version=3;" providerName="System.Data.SQLClient" />
</connectionStrings>
Now when I try to connect to the db from the project I get Exception saying "The given path's format is not supported". How do I set up the connection so that any change I make to the db stays in aswDB.db on the server? (I plan to connect it to a Xamarin.android app too)

How to package .sdf Database Application on CD and run without installing on machines

I am having a challenge that is specifically unique to me. I have browse the questions and answers catalog and what i found does not specifically address my scenario.
I created Windows Application on C#.Net with SQL Server CE at the back-end. I want the Application to be packaged in CD in such a way that my User will not install it rather will just insert and use the Application.
I have build the Application and copied the DB file, Application File, Configuration Files, Manifest Files and the .dll files to a folder and zipped it. Then copied the zipped folder to a CD ROM and run on a different system.
On the System I installed SQL Server CE Runtime installer. The Application executed successfully but when I attempted to submit a Form that is connected to the .sdf database the following exception was thrown:
The path is not valid. Check the directory for the database. [Path = C:\Users\John\AppData\Temp\Temp2_App.zip\App\Data\abc.sdf]
My Application Connection String at App.Config is:
<connectionString>
<add name="MyApp.Properties.Settings.MyAppConnectionString"
connectionString="DataSource =|DataDirectory\\abc.sdf|"
providerName="Microsoft.SqlServerCe.Client.3.5 />"
</connectionString>
The Connection Strings I used in my codes is:
string conString = "Data Source=|DataDirectory|\\Data\\abc.sdf";
Please what is it that I am getting wrong. Please help me.
Well, in the quest to finding a solution to the problem I have modified the App.Config Connection String to:
<connectionString>
<add name="MyApp.Properties.Settings.MyAppConnectionString"
connectionString="DataSource =|DataDirectory|\\Data\\abc.sdf"
providerName="Microsoft.SqlServerCe.Client.3.5 />"
And when I executed the Application on a user Machine it flag the exception - Access to the database file is not allowed. [File name = E:\App\Data\abc.sdf].

Publishing WPF application with a LINQ to class database

I have a WPF application holding a LINQ to class database, now I need to publish this application to work on client's machine.
I have done this but it doesn't work like if the database was not found, I think my problem is that the database is not included in the deployed files, so I need help with a clear steps to publish my application including my database.
Thanks in advance
It's not possible to interact with your .mdf database without having SQL Server engine installed on your client machine .
Try this:
Install SQL server Express on your Client machine
Attach database to the SQL Server (using .mdf or using a DB backup)
then change your connection string before deploying the application in client machine.
if you've hard coded the connection string then , you'll have to change the connection string to adjust client's machine name , or add you connection string inside app.config in order to give you the flexibly to modify it after deployment .
App.Config:
<configuration>
<connectionStrings>
<add name="Test" connectionString="Data Source=.;Initial Catalog=OmidPayamak;IntegratedSecurity=True" providerName="System.Data.SqlClient" />
</connectionStrings>
using
var connection = ConnectionFactory.GetConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString, DataBaseProvider);
wish it help .

ASP.NET Access denied for user (using password: NO) after deploy with msbuild/msdeploy

I'm setting up ci-deployment using jenkins for multiplice ASP.NET MVC 5 EF CF application with MySQL-Database on a Windows Server 2012 R2 node. The app gets compiled first using msbuild and then published on IIS with msdeploy. ConnectionStrings will be replaced using the -setParamFile parameter, which works.
The problem: After calling the app on the target server, I get the following MySQL error:
MySql.Data.MySqlClient.MySqlException: Access denied for user 'myUser'#'myIp' (using password: NO).
The MySQL-Doc say that this means the clinent had tried to connect without password.
This is really confusing me because my ConnectionString certainly contains a password! In the Web.config from the folder of the IIS-App it looks like this:
<add name="MyContext" connectionString="Server=SERVERIP;Database=MYDBNAME;Uid=DATABASEUSER;Pwd=PWD;Convert Zero Datetime=True;" providerName="MySql.Data.MySqlClient" />
Which is valid, because the app is running fine on local debugging and a Windows Server 2012 R2 based testsystem, where I deployed the app using Web-Publishing function of Visual Studio.
I have the suspicion that my Web.config gets overwritten, but can't find out where and why. I took a look in the local Machine.config file of the target-server, but in contrast to another thread with nearly the same problem this isn't containing my ConnectionString (And I even can't imagine why this should gonna happen).

LocalDB not found when deploying to a different machine

I'm having a problem switching a project I am working on over to another system. It's an ASP.Net web application and web form wrapped in a single solution, with a SQL .mdf DB file in the project as well. I'd like to be able to zip up the whole thing and move it around, but when trying to debug the solution on the other machine I get an error about the local DB not existing. My connection string in the Web.Config file looks like this:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-name-of-database.mdf;Initial Catalog=aspnet-name-of-database;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I know I must be making an obvious mistake, but I can't figure out what it is. Any advice, please? Thanks.
Edit: The specific error is:
"The specified LocalDB instance does not exist."
Run the following from your package manager console:
SqlLocalDb info
If the executable isn’t found, chances are you do not have LocalDb installed in your new machine. You can use the steps mentioned in the below link to debug as to why the connection is not successful to your localDB:
http://odetocode.com/blogs/scott/archive/2012/08/15/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True
Try setting the Datasource as below.
Data Source=.\;
If you are able to connect to your database, then the set the ServerName as DataSource in your connection string.
Make sure you have SSMS installed in your new system.
Download SQL Server Express 2014

Categories

Resources