Having issues deploying an .exe with a SQL Server CE database - c#

On my PC, I can read from the .SDF SQL Server CE database file just fine no matter where I place it, but it won't even log on if I send it to someone else to test.
Any ideas?
The current files:
Pizza Hut.application
Pizza Hut.exe
Pizza Hut.exe.config
Pizza Hut.exe.manifest
Pizza Hut.pdb
PIZZAHUT.sdf
And this is the app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="MAKESUSHIEntities"
connectionString="metadata=res://*/Datos.ModMakeSushi.csdl|res://*/Datos.ModMakeSushi.ssdl|res://*/Datos.ModMakeSushi.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\PIZZAHUT.sdf""
providerName="System.Data.EntityClient" />
<add name="Sistema_Restaurante.Properties.Settings.MAKESUSHIConnectionString"
connectionString="Data Source=|DataDirectory|\PIZZAHUT.sdf;Initial Catalog=MAKESUSHI;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
UPDATE: It does not works on my computer if I uninstall SQL Server CE 3.5. I placed the .dlls in the folder where the .exe and .SDF files are and it does not works. What are my options?

Related

This database cannot be imported. It is either an unsupported SQL Server version or an unsupported database compatibility

I am inserting data in my form but it is not updated in database. When I refresh the table data I am getting this error:
This database cannot be imported. It is either an unsupported SQL Server version or an unsupported database compatibility.
There are no errors in my code. According to other articles I set the "Copy to Output Directory" property of database to "Copy if Newer" too. Still it is giving me this error. How can I fix this error? What changes should I make? I am using visual studio 2015 and local database.
This is my connection string:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="dbx"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\db\Database.mdf;Integrated Security=True;MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>

c# configuration manager

Hello im having trouble with my connection when i transfer my code to another pc. Here in its original computer it is working fine. But in another computer it says connection error. Im sure about the new connection string on that pc is correct so i think it has something to do with configuration manager.
The other pc has same version of visual studio and sql express
App config code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="MPnew.Properties.Settings.MARISCHELLdatabaseConnectionString1" connectionString="Data Source=BENJOPC\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name ="cnn" connectionString="Data Source=BENJOPC\SQLEXPRESS;Initial Catalog=MARISCHELLdatabase;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
Connection code:
using (SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cnn"].ConnectionString))
{
if (cnn.State == ConnectionState.Closed)
cnn.Open();
// continue code
}
I think BENJOPC\SQLEXPRESS is giving wrong connection message. I suggest to use correct server name or you could just use .\SQLEXPRESS instead of BENJOPC\SQLEXPRESS.

How to embed database into final c# .exe file?

I have completed my project in c#. I have used SQL Server Compact database (.sdf file). Now, when I compile and run, it works fine. But, how will I be able to run the application in other computers without configuring the connection to database?
In your App.config file add the following after </configSections>:
<connectionStrings>
<add name="NameOfYourConnectionString" connectionString="Data Source=.; AttachDbFilename=|DataDirectory|\student.sdf;Initial Catalog=student; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

Dynamic sql connection string

I am using my SQL connection in my mvc4 application as follows:
public static string ConnectionString=#"Data Source=LocalDB)\v11.0;AttachDbFilename=C:\Users\..\Documents\Visual Studio 2012\Projects\..\..\App_Data\RoDB.mdf;Integrated Security=True";
I want to rewrite it as dynamically.
When I change the system, I don't want to change the connection string.
If you use ".\SQLExpress" as server name it will connect to the local instance. In that case you don't need to change your connection string on different machines.
You can put connection strings in your web.config file, this means it is out of application code and doesn't require a re-build to change.
<configuration>
<!-- Other config settings -->
<connectionStrings>
<add name="localDBConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\..\Documents\Visual Studio 2012\Projects\..\..\App_Data\RoDB.mdf;Integrated Security=True" />
</connectionStrings>
</configuration>
Then to use this in your application you can put the following in compiled code:
string myConnectionString = ConfigurationManager.ConnectionStrings["localDBConnection"].ConnectionString;
Whats wrong with using a web config? its pretty much standard practice I'd assume?
Also read up on using the relative path. EG. Relative to application location
add a app configuration file in you application and add setting inside it
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data Source=LocalDB)\v11.0;AttachDbFilename=C:\Users\..\Documents\Visual Studio 2012\Projects\..\..\App_Data\RoDB.mdf;Integrated Security=True"/>
</appSettings>
</configuration>
in your code you can write
string ConnectionString= System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();

Connecting to a SQL Server using Entity Framework 4

So on my development machine I have SQL Server Express and Visual Studio installed. I finished creating the application and everythings working. Here is the connection string in the App.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ColegioDBEntities"
connectionString="metadata=res://*/Repositories.ColegioModel.csdl|res://*/Repositories.ColegioModel.ssdl|res://*/Repositories.ColegioModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=ColegioDB;Integrated Security=True;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>
I created an installation project and want to install the application on a Virtual Machine (to simulate deployment conditions) which is on the same network as where the SQL Server Express is installed. What would the connection string be? Like, 192.168.2.102/SQLExpress?
Any ideas?
surely the IP address or host name will be needed then the instance name of SQL Express. Consider that by default SQL Express is installed with tcp and named pipes disabled so you have to enable those facilities in the configuration manager before you could access it remotely from another machine.
The sql connection string is part of the "connectionString" attribute and is encoded as a substring with masked quotes:
provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=ColegioDB;Integrated Security=True;MultipleActiveResultSets=True"
so the config for your ip adress must look like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ColegioDBEntities"
connectionString="metadata=res://*/Repositories.ColegioModel.csdl|res://*/Repositories.ColegioModel.ssdl|res://*/Repositories.ColegioModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=192.168.2.102\SQLEXPRESS;Initial Catalog=ColegioDB;Integrated Security=True;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>

Categories

Resources