I have a console application and in the App.config I need to add a connectionString to another SQL server that is in the same network.
If I try the connectionString to a local server by only passing the Server='localhost' its worked but I cannot make it work for an outside server.
Thanks
Here is the connection file
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
<connectionStrings>
<add connectionString="Server=LocalServer;database=DAtaBase;user=UserName;pwd=Password" name="Connection"/>
</connectionStrings>
</configuration>
Example connection to outer server:
<connectionStrings>
<add name="Namespace.Settings.outerSQL" connectionString="Data Source=192.168.0.100\SQLEXPRESS;Initial Catalog=database_name;User ID=user;Password=password"/>
</connectionStrings>
You need address to remote server and credentials provided (if it's not Windows auth, for which you use "Integrated Security").
inside of a app.config / web.Config file you would have the following and this is a simple and easy way to connect to a sql server database.. also confirm what database you are using because the connection string can be different depending on the DBMS
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DbConn" connectionString="Data Source=the name of your database;User Id=UserName;Password=Password;"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
Related
I'm having some difficulties to connect to SQL Server running on a virtual machine (virtualbox). I'm using ADO.NET in C# to do the connection through a connection string but I'm not having any success with this.
My app.config file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<connectionStrings>
<add name="AP3"
connectionString="Data Source=190.166.2.8,1433;Initial Catalog=AP3;
User Id=sa;Password=PasswOrd;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I don't know if I'm doing anything wrong...
It seems that you've not allowed Sql Server for Remote Connections. Kindly follow this link for more details
You can add DBMSSOCN to use TCP/IP instead of Named Pipes.Maybe it is a problem.
try this connection string.
"Data Source=190.166.2.8,1433;Network Library=DBMSSOCN;Initial Catalog=AP3; User Id=sa;Password=PasswOrd;"
My application runs only on .NET 2.0.
But, I had the following text in App.config in the deployed application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="assemblies"
type="Simple.Framework.AssembliesConfigurationSection, Simple.Framework"/>
</configSections>
<connectionStrings>
<add name="SystemSqlServer"
connectionString="Data Source=.\sqlexpress;Initial Catalog=gre;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
I replaced the supportedRuntime with the following text, as my application took a long time to start:
<supportedRuntime version="v2.0"
sku=".NETFramework,Version=v2.0"/>
But, I am getting the following message:
The following picture shows that .NET 2.0 is already installed:
and, my .net 3.5.1 is already turned on, and there is no additional option for .net 2.0.
i am trying to connect my local MySQL database to my windows form application using app.config.
but i am keep on getting the below mentioned Exception.Can anyone help me please.
Exception :
App.config be like :
<configuration>
<connectionstrings>
<!--<add name ="support_KB" connectionstring="server= .\sqlexpress;database=kbase_support;Integrated Security=SSPI" />-->
<add name ="MyConnectionstringname"
providerName="System.Data.SqlClient"
connectionstring="Data Source=.\sqlexpress;Initial Catalog=kbase_support;Integrated Security=SSPI" />
</connectionstrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
The tag name is case sensetive, it should be:
<connectionStrings>
...
</connectionStrings>
Note: System.Data.SqlClient is the provider for Microsoft SQL Server, not MySQL.
You have two end tags </configSections>. Remove the one before <connectionstrings>
And, <connectionstrings> is case sensitive. It should be <connectionStrings>
Two things to note here.
You are talking about MySql, but connection string looks like for MSSql.
When you initialize your SqlConnection object, make sure you are giving the right connection string name MyConnectionstringname
I have a class library where I store a connection string in the application settings:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="FAB.IMon.DataAccess.Properties.Settings.IMonConnectionString"
connectionString="X" />
</connectionStrings>
</configuration>
I implemented a WCF Soap service wich references this library. In my WCF service I want to use connection string Y. So I changed the web.config:
<connectionStrings>
<add name="FAB.IMon.DataAccess.Properties.Settings.IMonConnectionString"
connectionString="Y" />
</connectionStrings>
When I start the Webservice the service uses X instead of Y, why?
I am using VS2012. I have to keep connection string in app.config and have to access it from my cs file. But I am unable to do it in VS2012. Following is what I have found from net but I think it works on earlier version of VS not on VS2012.
app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="DataFormConnection"
connectionString="Data Source=abcdd;database=xyz;uid=4566;pwd=987"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
How I am accessing it:
connectionString = ConfigurationManager.ConnectionStrings["DataFormConnection"].ConnectionString;
Getting error: type or name does not exist in System.Configuration.ConfiguarationSettings
Go to references, and add a reference to System.Configuration.
Go to References, and add a reference to System.Configuration
Once you have done this, you should be able to reference System.Configuration.ConfigurationManager.