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.
Related
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?
I have an access database connected to my code via a connection string as shown:
connection = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Me\Documents\Visual Studio 2013\Projects\Computing Project\Database.accdb;
Persist Security Info=False;");
However I would like this app to be able to be installed on other devices, so I'm guessing the connection string has to be dynamic and change on each system. How would I use this in my code?
Add an App.config to the solution with following content
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<connectionStrings>
<add name="MyCon" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Me\Documents\Visual Studio 2013\Projects\Computing Project\Database.accdb; Persist Security Info=False;"/ >
</connectionStrings>
</configuration>
Then in code,
connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["MyCon"].ToString());
PS: ConfigurationManager class is in assembly System.Configuration.
So please add a reference of this assembly before using it.
I have inserted app.config file in my project.
Please help me out to overcome from this problem.
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="RConnString" connectionString="Data Source=C:\Users\user\Documents\Visual Studio 2010\Projects\Pathology lab\Pathology lab\bin\Debug\Pathology.sqlite"
providerName="System.Data.Sqlite" />
<add name="Pathology_lab.Properties.Settings.PathologyConnectionString"
connectionString="data source="C:\Users\user\Documents\Visual Studio 2010\Projects\Pathology lab\Pathology lab\bin\Debug\Pathology.sqlite;"
providerName="System.Data.SQLite" />
<add name="screen_shot.Properties.Settings.PathorecordConnectionString"
connectionString="data source="C:\Users\user\Desktop\screen shot\screen shot\bin\Debug\Pathorecord.db""
providerName="System.Data.SQLite" />
</connectionStrings>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
try to use this connection string
try to write connection string in |DataDirectory|/Databasename.db
And call App.domain () method
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();
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>