Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql connection string, global.asax or web.config

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Guys,

A very simple question...

I have the following line in my code...

MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("MyConnString"))

and i have

MyConnString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=XXXX;Initial Catalog=XXXX;DataSource=XXXX"

ok now what i dont know is--where to place this string? In web.config file or global.asax file??

-DNG
 
I always use the web.config.
Code:
<appSettings>
   <add key="<some name>" "value" = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=XXXX;Initial Catalog=XXXX;DataSource=XXXX"
/>
	</appSettings>
 
thanks for the reply...i set up the way you suggested...but i am getting Keyword not supported: 'provider'.

here is my sub...what is wrong with this:

Code:
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
			
Dim SqlConn As SqlConnection
Dim SqlCmd As SqlCommand
Dim strConnection As String

Try
strConnection=ConfigurationSettings.AppSettings("myconn")
SqlConn = New SqlConnection(strConnection)
SqlCmd = New SqlCommand("Select * from Mytable", SqlConn)
SqlConn.Open()
			
CodeSearchList.DataSource = SqlCmd.ExecuteReader()
CodeSearchList.DataBind()

Catch ex AS Exception
			 
Response.Write(ex.ToString & "<br>")
Finally
[red]SqlConn.Close()[/red]
End Try
		 
End Sub

if i dont comment the line in red then i get "Object reference not set to an instance of an object." and if i comment it then i get Provider keyword not supported error...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top