GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  ASP.NET 2.0
Go To First  |  Previous Question  |  Next Question 
 ASP.NET 2.0  |  Question 85 of 161    Print  
how to create a DB connection at one place/page so that we can use that connection for all pages/forms/windows.what r the steps ned to be performed.
if question not clear,let me know.
reply to my e mail id.

  
Total Answers and Comments: 3 Last Update: April 03, 2006     Asked by: rahul 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 19, 2005 23:38:13   #1  
pankaj shama        

RE: how to create a DB connection at one place/page so...
ASP.Net
 
Is this answer useful? Yes | No
October 21, 2005 10:34:09   #2  
Ranjit Srinivasan        

RE: how to create a DB connection at one place/page so...

<?xml version 1.0 encoding utf-8 ?>
<!-- Web.Config Configuration File -->
<configuration>
<appSettings>
<add key ConnectionString
value server localhost;database Northwind;uid sa;password secret; />
</appSettings>

<system.web>
<customErrors mode Off />
</system.web>
</configuration>

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class ConnString : Inherits Page

Protected dataGrid As DataGrid

Protected Sub Page_Load(ByVal Sender As Object ByVal E As EventArgs)
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim strConnection As String

Try
'Get connection string from Web.Config
strConnection ConfigurationSettings.AppSettings( ConnectionString )

sqlConn New SqlConnection(strConnection)
sqlCmd New SqlCommand( SELECT * FROM Customers WHERE _
& (CompanyName LIKE 'A ') OR (CompanyName LIKE 'B ') sqlConn)
sqlConn.Open()
dataGrid.DataSource sqlCmd.ExecuteReader()
dataGrid.DataBind()
Catch ex As Exception
Response.Write(ex.ToString & <br> )
Finally
sqlConn.Close()
End Try
End Sub

End Class


 
Is this answer useful? Yes | No
April 03, 2006 07:43:41   #3  
aruna        

RE: how to create a DB connection at one place/page so...
by specifying the connectionstring in web.config
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape