Publishing WPF application with a LINQ to class database - c#

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 .

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 can connect to host's db from host?

I bought a Windows hosting from GoDaddy. I have configured the configuration settings(Adding database and publishing project's files to host)
I can access the database while running the project on the local server.
But when I transfer the project to the server, the project on the server can't do it.
I wrote my connection string to web.config file, here it is:
<add name="xyz" connectionString="Data Source=IP ADDRESS;Initial Catalog=DBNAME;User ID=USERNAME;Password=PASS;Integrated Security=False" providerName="System.Data.SqlClient" />
I used MVC and Entity Framework, I also used layered structure
Thank You.
try to check more details about the connection string that should be used with your database provider. Here you can find several examples about how to create your connection string properly in SQL SERVER.
please notice that if you are working in your host machine, you have not to specify the IP ADDRES of your SQL SERVER but the SERVER NAME just like:
Data Source=(SERVER_NAME) \ DB_INSTANCE_NAME
I hope that it's gonna be useful.

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

C# Linq-to-sql server name when creating a release

I'm working on C# linq-to-sql application over SQL Server express 2008 . My database is inside SQL server.
I'm using Windows Authentication to connect to sql server from my application.
The server name used in connection string is related to my pc user name, so I'm wondering if I create a release of my application and put it on client pc which have SQL Server installed with another server name, would my application work?
my connection string is
<add name="WindowsFormsApplication1.Properties.Settings.OPTICA_MDFConnectionString"
connectionString="Data Source=ENG-MEDIAN-PC;Initial Catalog=OPTICA.MDF;Integrated Security=True"
providerName="System.Data.SqlClient" />
Because the app and the sql server are on the same host you can use "Data Source=.\<instance name>" which may be the default MSSQL.
That default would look like this:
connectionString="Data Source=.\MSSQL; ... "
For another example, our developer boxes' app.config uses this:
connectionString=".\DEVSQL;Initial Catalog=..."
Note that the "." is the host and that "DEVSQL" is the sql server instance name.

Cannot deploy application with SQL Server CE database.file

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

Categories

Resources