brian4342
brian4342

Reputation: 1253

Change connection string to use external MSSQL database

Let me briefly explain what I've done so far: I have created a basic ASP.NET MVC web application. I am using the included login features that is included when you create a new project. (I have also added some extra fields in the login/registration that I need). Currently it creates a local database in the AppData folder (see code below) however I need to access this database remotely once its been hosted.

<connectionStrings>
     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-HubSite-20141231121833.mdf;Initial Catalog=aspnet-HubSite-20141231121833;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

I have registered a domain with 123-REG and it shall be hosted with TSOHOST. TSOHOST have also created me an MSSQL database which I can use instead of the local one the application is using.

TSOHOST have given me the following information for the MSSQL database

Password: aaaaaaaaaa 
Database name: bbbbbbbbbb 
Database username: cccccccccc 
Server: 11.111.1.11
Remote IP: 22.222.22.2,2222

How can I adapt the connection string so that it points to this new database?

Thanks :)

Upvotes: 1

Views: 1233

Answers (3)

ioaoa
ioaoa

Reputation: 56

You would need to update the connection string values and include the username and password if this is not a trusted connection:

"Server=22.222.22.2,2222;Database=bbbbbbbbbb;uid=cccccccccc;password=aaaaaaaaaa" providerName="System.Data.SqlClient"

Here is a resource you may find helpful:

https://www.connectionstrings.com/sql-server/

Upvotes: 2

Philip Johnson
Philip Johnson

Reputation: 1081

Change your connection string so that the data source points at the new host.

Remove the attachdbfilenane section from the connection string.

You only need username and password, or integrated security true along with data source (the server) and initial catalog (the database) set.

Oh and ensure the firewall rules at the server side are set to only speak with your IP address if you have the database on the net and your client app somewhere else. I.e. The firewall rule needs to understand that requests from say port 1433 from this ip need to be routed through to the database server. If it's not working I suspect firewall rules might be the problem.

Upvotes: 0

Ellery
Ellery

Reputation: 1426

<add name="new-connection" connectionString="Server=11.111.1.11;Database=bbbbbbbbbb;User Id=cccccccccc;Password=aaaaaaaaaa;" providerName="System.Data.SqlClient" />

Upvotes: 0

Related Questions