Reply
ASP Coding connection to the server
Old 01-25-2007, 10:26 PM ASP Coding connection to the server
Junior Talker

Posts: 4
Name: Elisha Wong
<%
set adoConn = Server.CreateObject("ADODB.Connection")
set adoRS = Server.CreateObject("ADODB.Recordset")

adoConn.Open "DSN=trydata;UID=;PWD=;"
%>


Hi there~ Im newbie to asp and would like to ask some help about the server connection coding. What should I do in order for me to avoid the above connection coding type in every page of my website? Can I just save the above connection coding in one page, then when i create other page, i can just use a simple coding to call back that server connection page? Can anyone give me guidance / solutions on this? Thanks in advance..
Taurusgal83 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-25-2007, 11:31 PM Re: ASP Coding connection to the server
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,024
Name: Forrest Croce
Location: Seattle, WA
You can save that into an asp file, and use an include statement to refer to the file - sharing it across your whole app, being able to make changes to one file that automatically affect all the others. You're using ASP Classic, and I use ASP.NET, so I can't tell you the exact syntax, but I think it's just <% include file="somefile.asp" %> ... if not, it's very close, and MSDN can show you the exact syntax.

Another note is it looks like you used the ODBC manager in the Control Panel ( or under Admin Tools depending on the O/S ) to store the info needed to get to the database, and are referring to that file. You might want to think about just using a connection string instead. Say you want to move your application to another web site, or just another server. Now it's not only the code that needs to be moved.

It looks like you're probably either talking to SQL Server or MySql; you can just create a string that says:

adoConn.Open "Server=localhost; Database=myDB; UID=; PWD=;"

Then, when you move your application, the way to get to the database is part of your code, and it's that much simpler.
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 01-26-2007, 11:36 AM Re: ASP Coding connection to the server
bbutton's Avatar
Experienced Talker

Posts: 43
Name: Bill Button
Location: Reading,UK
Hi,

You can also use the global.asa file, if you do a quick search on Google you will find. But you could have something such as in your global.asa file.

<script language="vbscript" runat="server">
sub Application_OnStart
application("MyConnectionString") = "Server=localhost; Database=myDB; UID=; PWD=;"
end sub
</script>


Your connection coding would then look like

<%
set adoConn = Server.CreateObject("ADODB.Connection")
set adoRS = Server.CreateObject("ADODB.Recordset")

adoConn.Open application("MyConnectionString")
%>
bbutton is offline
Reply With Quote
View Public Profile Visit bbutton's homepage!
 
Old 01-26-2007, 11:51 PM Re: ASP Coding connection to the server
Novice Talker

Posts: 9
you can also save it to a file and include it in all your pages


<!-- #INCLUDE FILE="Connection.asp" --> for example
urbndk is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to ASP Coding connection to the server
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12750 seconds with 12 queries