Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



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

Posts: 4
Name: Elisha Wong
Trades: 0
<%
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
 
 
Register now for full access!
Old 01-26-2007, 12:31 AM Re: ASP Coding connection to the server
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
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.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 01-26-2007, 12:36 PM Re: ASP Coding connection to the server
bbutton's Avatar
Experienced Talker

Posts: 43
Name: Bill Button
Location: Reading,UK
Trades: 0
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")
%>
__________________
Bill Button

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
bbutton is offline
Reply With Quote
View Public Profile Visit bbutton's homepage!
 
Old 01-27-2007, 12:51 AM Re: ASP Coding connection to the server
Novice Talker

Posts: 9
Trades: 0
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 Search this Thread
Search this Thread:

Advanced Search

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

BB 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.20367 seconds with 12 queries