Hi All -
Prior to ASP .Net I use to create a connection object for SQL Server in my global.asa file and I would reference the obj whenever needed. how can I do the same in asp .net.
Here is my old asp sample:
Global.asa file:
Sub Session_OnStart
set session("conn") = createobject("adodb.connection")
session("conn").Open "PROVIDER=MSDASQL;DRIVER={SQL Server};SERVER=xxx.xxx.xxx.xxx;DATABASE=xxxxx_db;UID=xx;PWD=xxxxxxxx;"
End Sub
Call from Other Pages:
sqlstr = "select * from members WHERE memberid = '" & session("mbr_memberno") & "'"
set objRS = session("conn").Execute(sqlstr)
... How can I do this in .net?
rich
You can do a similar thing in ASP.NET using the global.asax file.Though, I would caution against it: check out this article for somereasons why you want to avoid this:
http://www.codeproject.com/asp/dbobjects.asp
Jason
|||
So is it better to just set session variables for servername, uid and pass so if it changes its in one file rather than shifting through tons of code replacing sql server names. Also if I do create a session var of these items can I call them in the vb.net portion of the code?
rich
|||web.config is the place to do it...there's an article on my blog on how to do it..check it out.|||The proper way to do it is to store the connection string itself in theweb.config (as the previous post suggests -- though others say thatstoring usernames and passwords in an unecrypted format is a bad idea-- trusted connections are better they say) and instantiate theconnection object and close the connection object on each page.Jason
|||
You can encrypt the connection string and put it in the web config. There's a good example of doing so here:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT08.asp
No comments:
Post a Comment