Connect to a database instance with many instance on the net - asp.net

I tried to connect to a SQL Server database on the internet via an Asp.net application that is on my local system.
The database is on a server with IP x.x.x.x and on the server we have 3 instances of SQL Server 2005: instance1/MSSQL2005 and instance2/MSSQL2005 and instance3/MSSQL2005.
I can't connect with my application to the instance1/sqlserver2005 on the database XXX on this instance !
This its my connection string that didn't work :
<add name="VestaWSEntities"
connectionString="metadata=res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl;provider=System.Data.SqlClient;provider connection string="server = x.x.x.x ;Data Source=Instance1\MSSQL2005;Initial Catalog=MyDB ;User ID=sa;Password=123;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />

Your instance names don't look correct.
Usually a SQL instance is specified in the format server\instance
given the information in the question, it should be something like
x.x.x.x\instance1
x.x.x.x\instance2
x.x.x.x\instance3
Can you connect to the instances in SSMS? You should use the same value in the data source in your connection string
Try replacing this in your connection string
server = x.x.x.x ;Data Source=Instance1\MSSQL2005;
to this
Data Source=x.x.x.x\instance1;Initial Catalog=MyDB;

Related

Is there anyway to connect to local SQL Server database from hosted website?

I create a website with a SQL Server database and put it on a host ...
I just want to know if there is a way that when I open my website on a special PC, I could connect to the PC's SQL Server database for reading and writing ...
Let me know if there is a special connection string for that !
You need to use server IP address and user id , password for connect to database.
Like
<add name="DefaultConnection" connectionString="Data Source=198.0.0.1;Initial Catalog=Database;user id=user1;password=[system];" providerName="System.Data.SqlClient" />
IP - 198.0.0.1
User id - user1
password - [system]
Note -
When you accessing your database from other computer , windows
authentication will not work.
Set sql server authentication in sql server
Allow remote connections to sql server
Allow Sql server port into firewall
Then try.

sql server 2012 allowing remote connection

I want to connect asp.net application hosted at a web server with sql server 2012 db hosted at another remote location.
I have enabled the TCP/IP on sql server, also set port 6322 for ip1 and ipall.
but if i go to my web server and telnet into the db server, no connection is established.
in ASP.net page just to test the connection i am using the connection string as below
<add name="DBConnectionStringTEST"
connectionString="Data Source=<db ip address>; Initial Catalog=<db name>; Persist Security Info=True;User ID=<username>;Password=<password>;connection timeout=0;Max Pool Size = 100;Pooling = True"
providerName="System.Data.SqlClient" />
my questions,
1) is there something i am missing, like wrong port.
2) do i need to give db ip address(client_net_address) or the actual db server address.
3) do i need to ask the server administrator to allow web server ip address to connect.
4) what is the quickest way to test if the web server can talk to the sql server without having to amend the connection string in asp.net application every time i make changes.
NOTE: i have searched other similar topic but couldnt find any answer which worked for me.
Without an explicit port or instance name specification, the default 1433 port will be used. Specify your custom port in the connections string:
<add name="DBConnectionStringTEST"
connectionString="Data Source=<db server ip address or host name>,6322; Initial Catalog=<db name>; Persist Security Info=True;User ID=<username>;Password=<password>;connection timeout=0;Max Pool Size = 100;Pooling = True"
providerName="System.Data.SqlClient" />
An easy way to test network connectivity is with TELNET:
TELNET <db server ip address or host name> 6322
This will show an empty console window if successful. Press ctrl-C to close.
You can also verify port connectivity with the Powershell command below if you don't have TELNET installed:
6322 | % { echo ((new-object Net.Sockets.TcpClient).Connect("<db server ip address or host name>",$_)) "server listening on TCP port $_" }
1) is there something i am missing, like wrong port.
From your posted connection string it looks like you are using default instance. if it's indeed named instance then provide the same info in your connection string.
2) do i need to give db ip address(client_net_address) or the actual
db server address.
It should be actual DB server IP address/Hostname along with Db server installed instance name.
3) do i need to ask the server administrator to allow web server ip
address to connect.
If you are providing correct IP addr/hostname/port/credential then it should allow you to connect through. (provided your DB admin have already created DB user for you)
4) what is the quickest way to test if the web server can talk to the
sql server without having to amend the connection string in asp.net
application every time i make changes.
By creating a UDL file. Open a notepad and save it as test.udl. Once saved -> double click the file -> provide all info and test the connection. It should look like below
EDIT:
To configure a universal data link (.udl) file
Double click on he file named test.udl
On Provider tab select SQL Server Native client 10.0
On Connection tab
enter BRR=SQL-N1 as Server Name
In Username and password section provide SA and password
Click on Test Connection
See Here for more information on this.

https sql server connection

I have a application using SQL Server 2008, the connectionstring works fine without https. However, when try to use https I get an error. I'm using the below string, am I supposed to add something else instead?
<add name="MyConnectionString" connectionString="Data Source=https://ServerName\QA01;Initial Catalog=DB_QA;Uid=abc;Pwd=xyz" providerName="System.Data.SqlClient" />
the only thing i did was add a https:// infront of the servername. it works fine without it, the db team told me SSL is setup on the db server.
I get the following error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
SQL Server does not connect via HTTP, and not via HTTPS as well. In other words, you are using the wrong syntax here.
Have you enabled SSL encryption for your SQL Server? This link tells you how its done: How to enable SSL encryption for an instance of SQL Server by using Microsoft Management Console
Then, you use the Encrypt statement in the connection string:
Using Encrypt=yes in a Sql Server connection string -> "provider: SSL Provider, error: 0 - The certificate's CN name does not match the passed value."

connect website to database on different server

There are 2 servers. Server A and Server B. My website is on Server A and my database is on server B. How can I let my website connect to server B's database in asp.net (C#)?
I think it should be set in web.config file. Assume the ip address on server B is 123.45.678.90 and my domain on server A is www.example.com (Will mssql.example.com be useful?)
SQL Server on Server B must allow Remote Connections and the TCP/IP protocol must be enabled and listing to the IP address of Server B. Then you can connect from Server A using the ip address of domain name.
Configure the protocols through the SQL Server Configuration Manager -> SQL Server Network Configuration -> Protocols for MSSQLSERVER (Assuming you have MSSQLSERVER instance)
Enable remote connections by connecting with SQL Server Management studio to the database and ask the properties of the Instance and go to 'Connections' there is an option ' Allow remote connections to this server'
Don't forget at last to check your firewall for port 1433. The connection string can be put in the web.config e.q.:
<connectionStrings>
<add name="myConnectionString" connectionString="server=ip-address;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
And in the C# Code the connection string can be accessed by using:
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
You'll need to create a connection string that points to that database. Here's an example on how to build one using an IP: http://www.connectionstrings.com/sqlconnection/connect-via-an-ip-address/
Here's instructions on how to place that string into your config file and read that into your code: http://www.connectionstrings.com/store-connection-string-in-webconfig/
These connection strings can then be used to run the SQL you need (for instance, creating an SqlConnection object and running commands with SqlCommand objects) like here: https://stackoverflow.com/a/10351647/70471

unable to connect asp.net application with godaddy.com sql server database

I have domain on the godaddy.com. I have create the database over there.I am able to connect to the database from godaddy.com site with specified user name and password. but when i am going to use same information in my connection string in my asp.net web application on local machine it is showing
"A network-related or instance-specific error occurred while establishing a connection
to SQL Server. The server was not found or was not accessible. Verify that the instance
name is correct and that SQL Server is configured to allow remote connections. (provider:
Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
This error.
my connectionstring is :
<add name="MyConnectionString"
connectionString="Data Source=myDataSource; Initial Catalog=MyDatabaseName; User ID=MyUserId; Password=MyPassword" providerName="System.Data.SqlClient" />
I have provided all required parameters to connection string here.I got this parameter information from godaddy.com database Description section.
You can't do that, their SQL server don't accept external connections.
[EDIT] OK, it seems that my first sentence is incorrect, look here:
http://community.godaddy.com/help/article/4978
http://community.godaddy.com/groups/web-hosting/forum/topic/ms-sql-remote-access/
http://help.godaddy.com/article/4977

Resources