Connecting ASP.NET to SQLServer,Somebody,Please!!

G

Guest

It is now 3 months that we are trying to connect ASP.NET to a SQLServer located on another system
However we act,we get a fatal error
We need someone to explain the way of connecting to SQLServer step by step from either VisualStudio.NET or FrontPage 2003
Our goal is to retrieve records from SQLServer and display them in ASP.NET pages,edit them,and return them to SQLServer
Thanx in advance.
 
G

Guest

I've included sample code below and you can use this with Visual Studio 2003. Make sure you make references to System.Data and System.Data.SqlClient in your class file. The crucial line is SqlConnection("server=oursqlserver;uid=sa;pwd=sapassword;database=master;") which contains the connection string. 'server' is the machine name of your SQL Server (e.g. SQLSERVER1, PLUTO, GSSQ1123); 'uid' is the Sql Server username, I recommed using "sa" (Sql Server Admin login) just as a test as you have higher chances of connecting as "sa"; 'pwd' is the associated password; 'database' is the database name you want to connect to, I've used "master" in this case as the database is guarenteed to exist in your Sql Server

[C#
using System.Data
using System.Data.SqlClient

public class WebForm1 : System.Web.UI.Page

private void Page_Load(object sender, System.EventArgs e

SqlConnection connection = new SqlConnection("server=oursqlserver;uid=sa;pwd=sapassword;database=master;")

// Open connectio
connection.Open()

// Perform all db operations her

// Cleanu
connection.Close()
connection = null



[Visual Basic
Imports System.Dat
Imports System.Data.SqlClien

Public Class WebForm
Inherits System.Web.UI.Pag
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Dim connection As New SqlConnection("server=oursqlserver;uid=sa;pwd=sapassword;database=master;"

' Open connectio
connection.Open(

' Perform all db operations her

' Cleanu
connection.Close(
connection = Nothin
End Su
End Clas

====
Rasika Wijayaratn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top