web.config connection string to different database server

6.9k views Asked by At

I have two conn strings in my web.config The second of them connects to external database - the database is on different server than the current website.

  1. Is it possible?
  2. How do I write my connection string?

I have this now:

<add name="newConn" connectionString="server=www.somedomain.com;database=dbname;user id=dbuser;password=dbpass" providerName="MySql.Data.MySqlClient" />

But I'm getting error saying:

Access denied for user 'dbuser'@'currentdnsserver.com' (using password: YES)

Thanks

3

There are 3 answers

0
nickornotto On BEST ANSWER

The connection I wanted to establish was between different hosting server (one on Windows, another on Linux).

My hosting provider told me it's not possible to connecto from Windows .NET website to Linux MySQL db. Not sure why but not possible.

Would be possible on the same hosting they said.

Thank you for trying to help @T McKeown

0
T McKeown On

You have 2 questions:

Answers:

1.  Absolutely.
2.  You will need to write a connection string that use TCP/IP as the transport.

To debug this you should try connecting via the SQL Server Mgmt Studio using the credentials you are using in the conn string.

I assume you are using SQL Server, here is a typical connection string to a TCP/IP enabled DBMS using SQL Server authentication.

<add name="conn2" connectionString="Database=myDB;Server=serverNameOrIpAddress;uid=id;pwd=pwd;" providerName="System.Data.SqlClient"/>
0
Tanyo Ivanov On

Yes, you can connect to remote server and this is used alot. The main thing that you should edit in your connection string is: Data Source.

Example:

Data Source=192.166.0.2;initial catalog=books;integrated security=False;user id=admin;password=!password1

Data Source: IP or URL of the computer you want to connect Initial Catalog: Name of the Database you want to use UserName and Password for the database user you want to use when you working with the database are required.