-1

I have my TCP port number, credentials and an IP address. How do I apply all of this to an app.config file to make it link to my database on another computer? I would like to apply it to my app.config file.

Darren
  • 17
  • 1
  • 10
  • 1
    Pretty hard to say when we have no idea what your application does or why it would need a TCP anything. – John Wu Aug 29 '17 at 02:51
  • Please elaborate as I'm pretty confused about what it is you're asking. – Kirk Woll Aug 29 '17 at 02:51
  • @JohnWu Hi this does not require to know how the what the application does.. Im researched before and it mentioned i need TCP port number – Darren Aug 29 '17 at 02:53
  • @KirkWoll I am asking how to configure the app.config file to link to the database i have on another server. Sorry for the typo in my question – Darren Aug 29 '17 at 02:54
  • Maybe check [this article](https://www.codeproject.com/Tips/416198/How-to-get-Connection-String-from-App-Config-in-Cs). – John Wu Aug 29 '17 at 02:56
  • connectionString="Data Source=ip adresss->project location.;Initial Catalog=Title;Integrated Security=True"/> – Darren Aug 29 '17 at 02:59
  • ^Do i put it like this? – Darren Aug 29 '17 at 02:59
  • If reading from config file (which so far looks like duplicate of question *as asked*) is not the problem you are facing make sure to [edit] your post to clarify what you know and what exactly you have problem with. If for example you looking for help constructing connection string make sure to show how other similar posts and https://www.connectionstrings.com/ did not solve your particular case. – Alexei Levenkov Aug 29 '17 at 04:12

3 Answers3

0

Make sure System.Configuration is referenced in your project.

To add database configuration in your webconfig: eg:

<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
    </startup>
      <connectionString>
        <add name="MyDatabase" connectionString="[Your connection string]"/>
      </connectionString>
</configuration>

To access it from C#:

var connectionString = ConfigurationManager.ConnectionStrings["MyDatabase"];
Xela
  • 2,322
  • 1
  • 17
  • 32
0

Specify data source in connection string with IP as below

data source=ip\sever instance
Gautam Savaliya
  • 1,403
  • 2
  • 20
  • 31
0
<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="sampleConnString" 
    connectionString="Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;"/>
  </connectionStrings>
</configuration> 

The key is the Network Library=DBMSSOCN; which tells your code to connect using TCP/IP. 1433 is the defualt port used by SQL Server (assuming your database is SQL Server). TCP/IP is often the best for a firewalled environment.

Abhay
  • 928
  • 1
  • 10
  • 28
  • Hi so if my TCP port number is different i put the port number there? – Darren Aug 29 '17 at 05:39
  • @Darren..provide some more information...your database? driver? – Abhay Aug 29 '17 at 05:46
  • not really sure but i was only told that my TCP port is using a certain number so how do i write for my TCP? My database is using SQL server but i am migrating it to mySQL – Darren Aug 29 '17 at 06:46
  • the port number i was given is 5000... – Darren Aug 29 '17 at 06:48
  • If you are connecting with SQL Server..then you can use above connection string..1) tcp:[\],......2)tcp:[\], (try these options in Data Source value) – Abhay Aug 29 '17 at 08:07