[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET CONNECT TO SQL SERVER DB

Posted on 2011-10-26
19
Medium Priority
?
237 Views
Last Modified: 2012-05-12
Hi,

I want to use a local SQL Server Db installed on my PC with an ASP.NET website that I will host with a hosting provider.

I know how to connect to the DB from my ASP.net code while I develop with Visual Studio on my PC (I have the name of the server) but I do not know what the name of my SQL Server will be once I want to access it from my code installed on the hosting provider. I guess that it is a matter of substituting the PC name with an IP address, but I do not know what that IP is or where to obtain it from.

Any help will be most welcome.

Thanks a lot in advance and regards.
0
Comment
Question by:robespierre_2010
  • 8
  • 4
  • 4
  • +1
19 Comments
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37030904
Place your connection string, or parts of it like dbserver, in the web.config.  Then you can tweak the settings at will without a recompile.

http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx
0
 

Author Comment

by:robespierre_2010
ID: 37031022
Hi,

Thanks for the fast response. The question, though had more to do with finding out what the connection string would be rather thatn with where to put the connection string. I mean, how to find out the IP of my DB.

Regards.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 37031091
run

ipconfig /all

on command line... for localhost you can use 127.0.0.1
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37031092
Sorry for that.

The DBA of the hosting provider should be able to provide you with the connect information once you get ready to host the app.

I'm not aware of anyway to legitimately walk a network 'looking' for databases hoping it finds the correct one if that is what you are asking.

Maybe another Expert will know of a way.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37031101
>>ipconfig /all

That will tell you the ip address of the local machine.  I believe the question is how to find an 'unknown' remote database server.
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37031169
You should be able to replace the server name value in the connection string with the ip address of your local machine which can be determined by using ipconfig /all
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 37031178
select @@servername
-->
MACHINENAME\SQLSERVER

once you know the name, use ping

ping MACHINENAME

to find the ip of server... but why do you need ip? name should be ok...
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37031181
jacko72,
ipconfig/all has already been suggested 12 minutes ago?
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37031203
@slightwv : Yes but you didn't then advise what to do with it, maybe you should spend more time reading the question and understanding it before posting answers that don't address the problem.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37031222
>>Yes but you didn't then advise what to do with it

I didn't post it.  I actually commented that in this question it wouldn't work since it was an unknown remote database not local.
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37031240
The question says : I want to use a local SQL Server Db installed on my PC, don't know where you are getting that is a unknown remote database. It is remote it terms that it is going to be remote from the hosted application but it is hardly unknown.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37031248
"but I do not know what the name of my SQL Server will be once I want to access it from my code installed on the hosting provider"
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37031421
Do you not think that statement should be interpreted as the SQL Server name will not be understood/resolved by the Hosting provider, why would he not know the name of his own sql server installed on his own PC. He needs to replace the name of the sql server with the IP address and instance name in the connection string e.g.
Server="192.168.1.1\myInstanceName"
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37031458
I took it to mean the app AND sql server database will be hosted.

I think we need to wait for robespierre_2010 to respond to clarify any outstanding issues.
0
 

Author Comment

by:robespierre_2010
ID: 37033939
Hi,

I tried using "ipconfig /all" but that does not give me the IP address, it only gives me the IPv4 which is 192.168.1.34 and that cannot be used to connect from the remote server, as fas as I know.

I went to www.whatismyip.com and I obtained an IP. But when I try to connect to my database from Sql Server Management Studio using "IP\INSTANCENAME" i still cannot connect.

Thanks again and regards.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37033974
Please clarify:

You will keep your SQL Server database local and Host a developed app that needs to point back into your local DB Server?
0
 

Author Comment

by:robespierre_2010
ID: 37033988
slightwv:You will keep your SQL Server database local and Host a developed app that needs to point back into your local DB Server?

Correct.
0
 
LVL 61

Expert Comment

by:HainKurt
ID: 37034252
you need a static ip, or dynamic dns name
get it from dyndns, something like

robesql.dyndns.info

so you can use this to connect to your sql... you need to setup your router and open sql port and route all incoming traffic to this machine
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 37034275
router : incoming port = 1433 --> 192.168.1.34
and assign static ip to your machine, check your router configuration to do this (assign this ip to this mac address)

after this config, when you try to connect to robesql.dyndns.info, it will go to your sql server...
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question