연결부분

dim dbconn
Set dbconn= Server.CreateObject("ADODB.Connection")
dbconn.CursorLocation = 3
dbconn.Provider = "MSDAORA"
dbconn.Provider = "OraOLEDB.Oracle" '변경
dbconn.Open "접속자", "접속자", "접속자"

코드부분

Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open "misuser.테이블명",dbconn,1,2,2
rs.addnew

rs.fields("필드") =값
rs.fields("필드") = 값

rs.update
rs.close

Set Rs = nothing

셀렉트 부분

Set St1 = Server.CreateObject("ADODB.recordset")
St1.Open 셀렉트쿼리 , dbconn,1,2,1

If Not St1.EOF Then

sDB_TEST= St1.fields("필드")
End If
St1.Close
Set St1 = Nothing

버추얼 인크루드

<!--#INCLUDE VIRTUAL="/INCLUDE/DB_OPEN.ASP"—>

 

데이터베이스 열기
Set dbconn = Server.CreateObject("ADODB.Connection")
dbconn ("Provider=SQLOLEDB.1;Password=비밀번호;Persist Security Info=True;User ID=mails;Initial Catalog=데이터베이스명;Data Source=서버아이피") 

디비저장
sql = " INSERT INTO TEST_TABLE(필드) VALUES(벨류)"
dbconn.Execute sql 

디비데이터 불러오기

Set rs= Server.CreateObject("ADODB.Recordset")
rs="SELECT * FROM TEST_TABLE"

rs.Open FileSql, dbconn , 1

do until rs.EOF
   Response.Write rs(0) ' 또는 rs("member_id")
rs.movenext

loop
rs.close

set rs = nothing
dbconn.close

//이전 URL 정보를 알고싶을때
server.URLEncode( Request.ServerVariables("HTTP_REFERER")))
예로 이렇게 사용하면 된다
If session("member_id") = "" Then
   response.Redirect("/login.asp?return_url="&server.URLEncode( Request.ServerVariables("HTTP_REFERER")))
   Response.End()
End If

 

image

asp 작업을 다보면 위와같이 표시되면 대략난감 ㅡ_ㅡ

image

이렇게 좀 친절하게 나와야지

자세한 오류 메세지 표시하기

7.0 부터는 보안이 강화되어서 “자세한 오류” 메세지가 표시가 안된다.

이를 표시하기 위해선 간단한 설정만 하면된다.

 

쭉 따로오삼

image

사이트의 ASP 클릭

image

 

주의

*만약 서버쪽 디버깅을 True 선택되있고 디버깅툴이 깔려있다면 서버에서 디버깅을 하기때문에 서버측에서 디버깅관련

메세지를 처리해야되기때문에 클라이언트에서는 계속 대기 타고 있다 주의!!

image

 

 

asp 설정이 끝났으면 오류페이지를 클릭한다.

 

image

오류페이지 –> 기능 설정 편집 클릭

image

“자세한 오류” 선택

디폴드값은 기본은 로컬 요청에 대한 자세한 오류와 원격 요청에 대한 사용자 지정 오류페이지(E) 이걸로 되있다

이거를 자세한 오류로 선택한다.

image

Failed to read binary data.

2003 서버에서는

c:\windows\system32\inetsrv\MetaBase.xml

MetaBase.xml 열어서 수정하면된다

AspMaxRequestEntityAllowed="10240000"

 

2008 서버에는 “최대 요청 엔티티 본문제한 크기 수정”

image

<%@ Language=VBScript %>
<HTML>
<HEAD>
</HEAD>
<BODY>

<%

'//에러코드 시작 상단에 두고
On Error Resume Next

%>

… 여기에 ASP 코드삽입

<%
'// 만약 에러가 있다면 메세지 보여주기
if err.number <> 0 then
response.Write("<b>err.description :</B>"&err.Description&"<br>")
response.Write("<b>err.number : </b>"&err.Number&"<br>")
response.Write("<b>err.Source : </b>"&err.Source&"<br>")
end if

%>

<%

file = Request.QueryString("FileName")

    strPath = Server.MapPath("/FILE_PDS")&"\"& File
'경로 설정

Response.AddHeader "Content-Disposition","attachment; filename=" & file  & """"
Response.ContentType = "application/x-msdownload"

Response.CacheControl = "private"

set objFS =Server.CreateObject("Scripting.FileSystemObject")

set objF = objFS.GetFile(strPath)

Response.AddHeader "Content-Length", objF.Size

set objF = nothing

set objFS = nothing

Set objStream = Server.CreateObject("ADODB.Stream")

    objStream.Open

    objStream.Type = 1

    objStream.LoadFromFile(strPath)

    download = objStream.Read
    Response.BinaryWrite download

    Set objstream = nothing

%>

Redim and Preserve in ASP Arrays

-배열 길이 값을 보전하면서 동적변환

-배열 길이 증감
When you're using ASP arrays, sometimes you want to make them larger part way through processing. The Redim command lets you alter an array size - and the preserve command saves the data already there.
Let's say you start out with an array that normally only needs around 5 items in it. So you could do
Dim ShopCart(5)
This would conserve memory space and take into account what most people would use it for. But let's say someone comes along who wants more than 5 items in their shopping cart! You don't want to lose that extra information. So to make the array size larger, you would say

 


Redim ShopCart(10) //요렇게 하면 기존의 값이 날라감

 


or whatever new size you wanted to bump it up to. One problem, though. A redim command loses any data currently in the array. This might be fine if you're just getting started, but if someone is halfway through shopping it'd be bad to lose their data. In that case, you would instead use -

 


Redim PRESERVE ShopCart(10) //요렇게 하면 기존의 값이 보관되고 길이도 변경됨

 


This keeps the array we had already and just adds more space to it.

ASP에서 BLOB필드에 저장된 이미지를 나타내는 방법

 

요약

Active Server Page(ASP)를 사용하여, BLOB필드에 저장된 Image를 Internet Browser에서 볼 수 있다. 아래의 예제는 Microsoft SQL Server sample database table인 pub_info에 저장된 GIF 이미지를 보여주는 방법을 보여준다.

추가 정보

대부분의 Internet browser들은 GIF와 JPEG 이미지를 지원한다. 이미지를 보여주기 위해서, 브라우저는 웹 서버로부터 이미지를 요청한다. 서버는 HTTP헤더의 MIME형식을 IMAGE/GIF 또는 IMAGE/JPEG를 포함함으로써, 이미지를 브라우저로 보낸다. 이러한 작업들을 Active Server Page를 이용하여 가능하다. 다음의 예제는 이미지에 대한 HTTP헤더를 작성하고 GIF파일을 브라우저에 제공하기 위해서 SQL서버에 있는 Image필드에 있는 이진 정보를 사용한다.

FILE: SHOWIMG.ASP
   <%@ LANGUAGE="VBSCRIPT" %>
   <%
   ' Clear out the existing HTTP header information
   Response.Expires = 0
   Response.Buffer = TRUE
   Response.Clear
 
   ' Change the HTTP header to reflect that an image is being passed.
   Response.ContentType = "image/gif"
 
   Set cn = Server.CreateObject("ADODB.Connection")
   ' The following open line assumes you have set up a System DataSource
   ' by the name of myDSN.
   cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"
   Set rs = cn.Execute("SELECT logo FROM pub_info WHERE pub_id='0736'")
   Response.BinaryWrite rs("logo")
   Response.End
   %>

위의 스크립트는 화면에 이미지만을 보여준다. HTML이나 ASP 문서로부터 이미지를 보여주려고 한다면 <IMAGE> 태그 안에 위의 파일을 참조한다.예를 들어, 이미지를 이 이미지를 설명하는 텍스트와 함께 화면에 나타내려면 다음과 같은 HTML페이지를 사용한다.

   <HTML>
   <HEAD><TITLE>Display Image</TITLE></HEAD>
   <BODY>
   This page will display the image New Moon Books from a SQL Server 6.5
   image field.<BR>
   <IMG SRC="SHOWIMG.ASP">
   </BODY>
   </HTML>

 

이 방법은 다른 형식의 이진 데이터에도 적용할 수 있다. 이를 위해 필요한 것은 표현될 Content의 형식이 무엇인지를 브라우저에게 알려주는 것이다. Response.ContentType에 적절한 Mine형식을 설정함으로써 브라우저에게 Content형식을 알려줄 수 있다. 예를 들어, 워드 문서를 나타내기 위해서는 ContentType = "application/msword"으로 설정한다. 

Free Code

We have posted here and on FreeVBCode.com various Visual Basic and C#.NET code samples to help fellow developers.

Sample Add-In
Rijndael AES Block Cipher
MD5 Digest - VB, VBScript (ASP), and JavaScript versions
SHA-256 Digest - VB and VBScript (ASP)versions
FrezCrypto
ZLib Wrapper
String Sort
Path Routines
Domain Search
Create and Validate License Keys
Replacement for VBs SaveSetting and GetSetting
Custom Message Box - Replacement for VBs MsgBox Function

You may not redistribute any of the following free code as 'sample' or 'demos'. However, you are free to use the source code or components in your own code, but you may not claim that you created any of the sample code or compiled components found on this site. It is also expressly forbidden to sell or profit from any of the sample code or compiled components other than by the knowledge gained or the enhanced value added by your own code.

If you use any of the source code or compiled components on this site, you realize that you do so at your own risk. The code and components provided here are supplied as is without warranty or guarantee of any kind.

Should you wish to commission some derivative work based on the code provided here, or any consultancy work, please do not hesitate to contact us; sales@frez.co.uk

You can send bug reports, enhancement requests, or just general comments to phil.fresle@frez.co.uk

Sample Add-In VBAddInDemo.zip (25KB)

This sample Add-In demonstrates how to write an Add-In for Visual Basic 6.0. It provides some of the functionality you will find in our VBCodeHelper product that can be found at http://www.vbcodehelper.com.

Rijndael AES Block Cipher (VB Version) rijndaelvb.zip (13KB) (Updated 19-Apr-2001)

The zip file contains two implementations of the Rijndael AES Block Cipher based on the C code version published by Mike Scott. One is a VB 6.0 Class, the other a VBScript ASP version, both come with some test code that shows how to use them. Updated 03-Apr-2001 with two new methods and demo code that shows how to encrypt/decrypt strings. Updated 19-Apr-2001 to fix bug with 256 bit keys.

MD5 Digest - VB, VBScript (ASP), and JavaScript versions MD5.zip (17KB)

The zip file contains both VB6 and ASP (VBScript) versions of code for generating an MD5 'digest' or 'signature' of a string. In addition, a JavaScript version has now been included thanks to Enrico Mosanghini. The MD5 algorithm is one of the industry standard methods for generating digital signatures. It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm. A common use for MD5 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.

Rijndael AES Block Cipher (C#.NET Version) rijndaelcs.zip (374KB) (Updated 13-Jul-2005)

The zip file contains a C# implementation of the Rijndael AES Block Cipher based on the C code version published by Mike Scott.

MD5 Digest - VB, VBScript (ASP), and JavaScript versions MD5.zip (17KB)

The zip file contains both VB6 and ASP (VBScript) versions of code for generating an MD5 'digest' or 'signature' of a string. In addition, a JavaScript version has now been included thanks to Enrico Mosanghini. The MD5 algorithm is one of the industry standard methods for generating digital signatures. It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm. A common use for MD5 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.

SHA-256 Digest - VB and VBScript (ASP) versions SHA.zip (14KB)

The zip file contains both VB6 and ASP (VBScript) versions of code for generating a SHA-256 'digest' or 'signature' of a string. The SHA-256 algorithm is one of the industry standard methods for generating digital signatures. It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm. A common use for SHA-256 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.

FrezCrypto FrezCrypto.zip (Version 1.2 - 18KB)

FrezCrypto is an ActiveX DLL component that wraps the Microsoft CryptoAPI and provides the user with methods to encrypt or decrypt strings. The user has the option of Block (RC2) or Stream (RC4) encryption. The encrypted data can be returned (or supplied for decryption) either as a string (complete with all manner of control characters) or converted to a hex format where each character is converted to the hex of its ascii value. The download contains the DLL, the Visual Basic code for the DLL, and some Visual Basic code that exercises the methods and shows how it maybe used.

Follow this link for a FAQ on FrezCrypto

Zlib Wrapper ZLibWrapper.zip (31KB)

Zlib Wrapper is a Visual Basic module and test harness that wraps the Zlib DLL as provided at the following web site; http://www.gzip.org/zlib/
The Zlib library is free and available for a number of different platforms, it provides a lossless compression routine and is useful for large strings containing duplicate data to some extent, for instance XML documents.

String Sort StringSort.zip (Version 1.1 - 5KB)

The string sort routines are contained in a Visual Basic module. The module includes algorithms for Quick Sort, Merge Sort, Insert Sort and Selection Sort. However, it is recommended that you use Quick Sort all the time as this 'non-standard' routine delegates to Insert Sort for small arrays and chunks.

Path Routines PathRoutines.zip (5KB)

Routines for path manipulation using the shlwapi.dll type library that comes with Internet Explorer. Comes complete with test harness.

GetRelativePath demonstrates when given a directory path and a file path how to return the relative path from the directory to the file.

GetCompactPath demonstartes how to compact a long path name down into a small space in order to display it effectively in, say, a small text box.

DomainSearch DomainSearch.zip (8KB)

An application that will do a smart search of the INTERNIC and NOMINET registrars for available .COM and .CO.UK domain names. The code could easily be extended to search other domains.

Create and Validate License Keys Registration.zip (19KB) (Version 2 - 27-May-2001)

The included classes and test form demonstrate three different methods on how you can generate license keys (such as the CD keys on the case of most Microsoft software) and test their validity for your applications.

Method 1: A 17 character numeric key. Simple technique, but could be guessed using a brute force attack.

Method 2: Generates a 25 character alpha-numeric key, the first 9 characters are completely random, the next 16 are based on an MD5 digest of the first 9 random characters plus an application specific string. 35,184,372,088,832 different possible keys for an application, extremely difficult to crack or guess.

Method 3: Generates a 16 character alpha-numeric key based on an MD5 digest of a supplied registered user name and an application specific string. Generates a key that is extremely difficult to crack where you know the name of the registered user.

Replacement for VB's SaveSetting and GetSetting RegSettings.zip (3KB)

This module contains two procedures; SaveStringSetting and GetStringSetting. These procedures can be used as replacements for VB's SaveSetting and GetSetting so that your data is written to the more useful 'HKEY_LOCAL_MACHINE\SOFTWARE' rather than the 'HKEY_CURRENT_USER\Software\VB and VBA Program Settings' key.

Custom Message Box - Replacement for VB's MsgBox Function CustomMB.zip (14KB)

This is a replacement for VB's standard MsgBox so that you can have a message box that is in the same style as the rest of your application (i.e. font size, colour, button size). It has an identical interface to VB's own MsgBox and so can be easily integrated into existing applications.

It also allows you to have non-standard message boxes by defining your own captions for buttons. There is an example that demonstrates displaying errors and including a 'Copy' button that copies the text to the clipboard so the user can paste the message into an email or document. 

Function stripHTML(strHTML)

    Set objRegExp = New Regexp

        objRegExp.IgnoreCase = True

        objRegExp.Global = True

        objRegExp.Pattern = "<.+?>"

        strOutput = objRegExp.Replace(strHTML, "")

        stripHTML = strOutput

    Set objRegExp = Nothing

End Function

+ Recent posts