Solved

asp.net and remote sql server database

Posted on 2014-09-21
11
16 Views
Last Modified: 2016-06-13
How do I add a sql server remote database connection to some asp.net code on my computer?
0
Comment
Question by:michaeldean99
  • 3
  • 2
  • 2
  • +3
11 Comments
 
LVL 14

Accepted Solution

by:
quizwedge earned 200 total points
ID: 40335533
Are you looking to view the remote database in Visual Studio? If so, check out http://weblogs.asp.net/nannettethacker/creating-a-database-connection-to-a-remote-sql-server-database-within-visual-web-developer

If you're looking to add a connection string to your code so that your code can access the remote server, check out http://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx
0
 
LVL 12

Assisted Solution

by:Ramkisan Jagtap
Ramkisan Jagtap earned 100 total points
ID: 40335985
Modify your connection string as below :

<connectionStrings>                                
  <add name="DefaultConnection" providerName="System.Data.SqlClient"
       connectionString="ServerName ,port;Integrated Security=False;User ID=XXXX;Password=XXXX" />
</connectionStrings>
0
 
LVL 1

Expert Comment

by:VijayBalkawade
ID: 40336287
It is same as you do for your local database. You have to provide remote SQL server instance name in connectionstring.
0
 
LVL 11

Expert Comment

by:LordWabbit
ID: 40336574
You could also add a linked server.
0
 
LVL 6

Assisted Solution

by:Mandeep Singh
Mandeep Singh earned 100 total points
ID: 40338300
HI,

if sql server box is located on a remote area, then you have to open Port between two machines on which sql server is running.

also make a connection like this.

<?xml version="1.0"?>
<configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>
  <connectionStrings>
    <add name="con" connectionString="Data Source=.;User ID=abc;Password=abc@123;Initial Catalog=AdventureWorks2008R2"/>
  </connectionStrings>

</configuration>
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:michaeldean99
ID: 40347449
hi
Using ms visual studio express 2013 for Web.
Have added the remote sql sever definition using the server explorer.
I assume that I have to add sql queries to the sql server object explorer?

Sample page
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>xxxxxx</title>  etc.

</head>
<body>
    <table style="width:100%" align="center">.....
     
How do I add the query results to the code?

thanks
0
 
LVL 14

Assisted Solution

by:quizwedge
quizwedge earned 200 total points
ID: 40388025
Saw that no one has responded yet. There are a bunch of different ways to add database query results to the code.

Some people prefer LINQ (https://code.msdn.microsoft.com/LINQ-Sample-Queries-13a42a54)

You can also use data layers. See the YouTube video at https://www.youtube.com/watch?v=JOJV-Z7cmkc starting at around 19:44

Yet another way is using OleDbDataAdapter (https://support.microsoft.com/kb/821765?wa=wsignin1.0)

I'd look over those three and choose the one that seems easiest and best for your project.
0
 

Author Comment

by:michaeldean99
ID: 40396606
thanks
Linq seems to be the obvious
0
 
LVL 11

Assisted Solution

by:LordWabbit
LordWabbit earned 100 total points
ID: 40396667
Well LINQ to SQL is a bit outdated (would still work though) the Entity Framework has replaced it.
0
 

Author Comment

by:michaeldean99
ID: 40396784
thanks LordWabbit
Entity Framework looks interesting
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now