Tuesday, December 4, 2007

How to reduce duplicate data from a recordset

How to reduce duplicate data from a recordset

To reduce duplicate data from a recordset

You can reduce duplication in your data through the use of DISTINCT in your SELECT statement.

<%

set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DSN=tenderproject;UID=tenderproject;PWD=tender"

set rs=Server.CreateObject("ADODB.Recordset")

sqlstr = "SELECT DISTINCT name, expertise from mytable ORDER BY name "

rs.open sqlstr, conn, 1,3

%>

Edited By: Norasyikin Mahmud

© 2001 ISC/Inner Esteem

All rights reserved. All other product names and trademarks are registered properties of their respective owners.

140302


How to use SELECT...MULTIPLE or a group of same-named checkboxes and turn it into a query

How to use SELECT...MULTIPLE or a group of same-named checkboxes and turn it into a query

To use SELECT...MULTIPLE or a group of same-named checkboxes and turn it into a query

When you want to select multiple options for a query, this is what you should do.



Select one or more makes:


Check the years you want to see reports for:
1997
1998
1999
2000
2001



<%

years = Request("ReportYear")
SQL = "SELECT make, reportYear, rating, comments " _
& "FROM carReportsTable " _
& "WHERE reportYear IN (" & years & ")"


Set RS = yourConnection.Execute( SQL )

%>

Now, that you have finished, you can use multiple values for your query.

What do you get when open a recordset

What do you get when open a recordset

Why do you get "The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another" when I try to open a recordset.

That’s because you have provided undefined parameter to your recordset Open method.

You can try using including the adovbs.inc file.

Or

Use the numeric constant to replace your adOpenforwardOnly, asLockOptimistic, adCmdTable.


How to use LCD to locate time

How to use LCD to locate time

To use LCD to locate time

When we work with database we will be confronted with many situations whereby we cannot standardize on a single data time and number format.

For example, we might save as date of 04/12/2001 as 04 December 2001.

We can do so by using the following codes.

<%

Session.LCID = 1061

Dim mydate

mydate= Formatdatetime(date,1)

response.write(mydate)

%>

How to read your system registry

How to read your system registry

To read your system registry

To access the system register we can take advantage of the system stored procedure that come with MSSQL Server.

These are the codes that will allow such operation.

<% Option Explict %>
<%

Dim objConn

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.ConnectionString = "DSN=pubs;UID=sa;PWD=;"

objConn.Open

'Must use the master database, where xp_regread exists...

objConn.Execute "USE MASTER"

Dim strSQL

strSQL = "xp_regread 'HKEY_LOCAL_MACHINE'," & _

"'SOFTWARE\Microsoft\MSSQLServer\Setup'," & _

"'SQLPath'"

Dim objRS

Set objRS = objConn.Execute(strSQL)

Response.Write "SQL Server installed at " & objRS("Data")

objRS.Close

Set objRS = Nothing

objConn.Close

Set objConn = Nothing

7%>

How to use set in MSSQL

How to use set in MSSQL

To use set in MSSQL

Here’s an example of the codes that allows us to do set in SQL

SELECT * FROM MYTBL WHERE USERID IN (5, 6, 7, 8, 9, 10)

By using this we are able to reduce a lot of coding such is OR , IF and FOR

Similarly, if we want to delete we can do the following

DELETE FROM mytbl
WHERE USERID IN (5, 6, 7)

How to create database table with ASP

How to create database table with ASP

To create database table with ASP

To create the database table with ASP, you need to do as followed.

<%

set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DSN=tenderproject;UID=tenderproject;PWD=tender"

set rs=Server.CreateObject("ADODB.Recordset")

sqlstr = "CREATE TABLE mytbl ( userid int, name varchar(30))"

rs.open sqlstr, conn, 1,3

%>

How to avoid getting the message Lock Time out

How to avoid getting the message Lock Time out

To avoid getting the message Lock Time out

If you have encounter the problem of record locking even through you have not tried to update the record then you can issue these select command instead.

SELECT COUNT(UserID)
FROM Users WITH (NOLOCK)
WHERE Username LIKE 'foobar'

This will ask MSSQL to ignore the lock and read directly from the table.

This will also help in designing your website to avoid your viewer from getting this message even though they just want look at your website

How to use ASP to retrieve System Objects in MSSQL Server How to use ASP to retrieve System Objects in MSSQL Server How to use ASP to retrieve System

How to use ASP to retrieve System Objects in MSSQL Server

To use ASP to retrieve System Objects in MSSQL Server

Because MSSQL store tables and column information in its table called syscolumns and sysobjects, it would be great if you can explore these tables without modifying it.

An example of ASP code to retrieve system objects stored here is

strSQL = "SELECT syscolumns.name, syscolumns.type, syscolumns.length, " & _

"syscolumns.isnullable FROM sysobjects " & _

"INNER JOIN syscolumns ON sysobjects.id = syscolumns.id " & _

"where sysobjects.name = '" & strTableName & _

"' ORDER BY syscolumns.colid"

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open strSQL, objConn

do while <> objRS.eof

response.write(" Name " & objRs("name") & " objRs("length") & " Allow Null" & " objRs("isnullable" & " ")

response.write("
")

loop

How to get the value of your @@IDENTITY from SQL Server

How to get the value of your @@IDENTITY from SQL Server

To get the value of your @@IDENTITY from SQL Server

Let’s say that you have set one of your columns to identity increment to a value and you want to retrieve the value of your last insert data.

Here’s the code to do it.

Dim Conn, lsSQL, loRs
Set Conn = CreateObject("ADODB.Connection")

' Open a connection to the database
Conn.Open("DSN=mydb;UID=user;PWD=password;")

' Insert a new record into the table
lsSQL = "SET NOCOUNT ON;" &_
"INSERT INTO tMembers (MemberName) VALUES ('Manohar');" &_
"SELECT @@IDENTITY AS NewID;"

' Execute the SQL statement
Set loRs = Conn.Execute(lsSQL)

' Get the inserted ID
llID = loRs.Fields("NewID").value

' Close the connection
Conn.Close()
Set Conn = Nothing

SET NOCOUNT function disable the output messages like ‘1 rows affected" from MSSQL Server.

How to Distributed Query on the fly

How to Distributed Query on the fly

To Distributed Query on the fly

If you have not setup your linked server or some changes has been made to the server you can issue SQL on the fly through.

set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DSN=tenderproject;UID=tenderproject;PWD=tender"

set rs=Server.CreateObject("ADODB.Recordset")

sqlstr = SELECT * FROM OPENROWSET("SQLOLEDB","192.168.0.1","RemoteUser","RemotePassword", "SELECT * FROM Database.dbo.table")

rs.open sqlstr, conn, 1,3

Notice that you only use OPENROWSET instead of the OPENQUERY statement.

How to issue Distributed query

How to issue Distributed query

To issue Distributed query

If you have added in a Linked Server you can issue query to your linked server by using the following codes.

set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DSN=tenderproject;UID=tenderproject;PWD=tender"

set rs=Server.CreateObject("ADODB.Recordset")

sqlstr = SELECT * FROM OPENQUERY(ServerAliasName,"SELECT * FROM Database.dbo.table")

rs.open sqlstr, conn, 1,3

How to create a downloadable file

How to create a downloadable file

To create a downloadable file

Let’s say that you want to export your data from SQL Server to a file and make it available for downloading. Here’s how you should do it.

<%

If Request.Form("action") = "Download File" Then

shortfile = "authors" & Session.SessionID & ".xls"

file = Server.MapPath("/virtualpath") & Session.SessionID & ".xls"

strSQL = "EXEC xp_cmdshell '" & _

"bcp pubs..authors out " & file & " -c -Sservernameorip -Uusername -Ppassword'"

strConn = "Provider=SQLOLEDB;Data Source=mydb;User ID=userid;Password=password"

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open strConn

objConn.Execute(strSQL)

objConn.Close

Set objConn = Nothing

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

If objFS.FileExists(file) Then

%>"%>Download Now <%

End If

Set objFS = Nothing

End If

%>

What is the difference between Remote Server and Linked Server

What is an AbsolutePage property

What is an AbsolutePage property

An AbsolutePage property

AbsolutePage properties allow you to set number of page (not record) of a data retrieval or search results. By manipulating this, it will allow you to set the page number. For example PageSize sets your first 10 records, to go to record 20, you can use AbsolutePage to set it to 20, 30 or 40.

How to use PageSize Properties

How to use PageSize Properties

Use PageSize Properties

Set rs3 = Server.CreateObject("ADODB.Recordset")

sqlstr3 = "SELECT * FROM ANNTEXT ORDER BY anndate DESC"

rs3.open sqlstr3, conn, 1,3

rs3.pagesize = 5

for intrec = 1 to rs3.pagesize %>

<%="rs3(">'> <%=rs3("heading") %>

<%

rs3.movenext

next %>

What is the use of Pagesize properties

What is the use of Pagesize properties

Use of Pagesize properties

The PageSize properties are used to set the number of record that a page should contain. A good example is the search engine that allows you to set the number of search result to be displayed in a single page.

How to use AND OR operator

How to use AND OR operator

Use AND/OR operator

In ASP and MSSQL Server you use the AND and OR operator just like you have used in the Query Analyzer to retrieve data that meet certain requirements

Set cn = Server.CreateObject("ADODB.Connection")

cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"

Set rs = Server.CreateObject("ADODB.Recordset")

‘ using the AND operator

SQLstr = "Delete * from employee where YEAR_BORN= 1980 AND Address=’California’"

‘ it’s like SQL statement in your SQL analyzer

Rs.open SQLstr, cn, 1,3


How to get your data faster with data cache

How to get your data faster with data cache

To get your data faster with data cache

If you want to speed up your data retrieval rate you can use data caching to improve the performance of your database.

Here’s how:

sub cachedata()

dim rsData, aData

' Put valid data into application("GLOBAL_SHIPPING_UPDATE")

if (not isdate(application("GLOBAL_SHIPPING_UPDATE"))) then

application.lock

application("GLOBAL_SHIPPING_UPDATE") = #12/31/1990#

application.unlock

end if

' If last update more than 5 minutes old then refresh

if (abs(datediff("n", application("GLOBAL_SHIPPING_UPDATE"), now())) >= 5) then

' Get data

set rsData = server.createobject("adodb.recordset")

rsData.open "select * from ShippingMethod", DBCONN

if (not rsData.eof) then aData = rsData.getrows()

rsData.close

set rsData = nothing

' Store in global memory

application.lock

application("GLOBAL_SHIPPING") = aData

application("GLOBAL_SHIPPING_UPDATE") = now()

application.unlock

end if

end sub

Displaying the results.

sub drawMethods()

dim aData, i, sMethod, sDescription

' Get the latest data

call cachedata()

aData = application("GLOBAL_SHIPPING")

if (not isarray(aData)) then

response.write "Error: No data available."

exit sub

end if

response.write ""

end sub


How to enable the connection pooling

How to enable the connection pooling

To enable the connection pooling

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\ASP\Parameters\StartConnectionPool

Please set this variable to 1

How to set the connection pooling timeout

How to set the connection pooling timeout

To set the connection pooling timeout

\HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\SQL Server\CPTimeout = 30

How do you need to know about ODBC connection pooling

How do you need to know about ODBC connection pooling

ODBC connection pooling

ODBC 3.0 handles connection pooling that allows OLEDB and ADO to take advantage of its functionality. But ODBC connection pooling might results in a bad connection pooling that reduce much of your resources. ODBC connection pooling turns on or off on a per process basis. Connection pooling allows many processes using the same connection configuration to be shared.

Embedding English Query in your ASP application

Embedding English Query in your ASP application

Embedding English Query in your ASP application

Embedding MSSQL Server English in your ASP can be done through the following codes.

Set eqsession = Server.CreateObject("mseq.session")

Using PivotTable Service

Using PivotTable Service

PivotTable Service

PivotTable is the main interface interacting with SQL Server Analysis Service. It can be called through ASP using the following codes

Set cell = Server.CreateObject("ADOMD.CellSet")

What if you result is exceptionally slow

What if you result is exceptionally slow

Result is exceptionally slow

If you have used stored procedure to retrieve let’s say 1500 number of records, it is unacceptably slow, you might want to consider using ASCII instead of returning HTML tags. It can be done by using the

 tag.

Why use store procedure

Why use store procedure

Use store procedure

By using stored procedure in executing your search criteria it will speed up the entire process as stored procedure is precompiled in nature.

How do you run a system stored procedure

How do you run a system stored procedure

Run a system stored procedure

To run a system-stored procedure, you can use the following codes.

'OPEN CONNECTION AND GET RECORDSET
Set objADOConn = Server.CreateObject("ADODB.Connection")
objADOConn.Open "dsn=webPUBS;uid=sa;pwd="
Set objRst = Server.CreateObject("ADODB.Recordset")

'GET RECORDSET VIA STORED PROCEDURE
strSQL = "EXEC sp_helpdb"

objRst.Source = strSQL

Set objRst.ActiveConnection = objADOConn
objRst.Open

What is the role of MTS (Microsoft Transaction Server )

What is the role of MTS (Microsoft Transaction Server )

Role of MTS (Microsoft Transaction Server )

MTS provide a means of ensuring the stability of the occurrence of transaction. It strive to ensure that

- If the transaction is successful, all the data is correctly updated

- If the transaction fails, changes made will be aborted

What is the basic data access component

What is the basic data access component

Basic data access component

Here’s a bit of information that will allow you to differentiate between these 3 data access components.

Microsoft OLE DB is "middleware" that sits between the Web client and the server to translate standard OLE function calls into database specific calls that a certain back-end database driver (for database engines SQL Server, Oracle, or Access) will understand. Essentially, OLE DB on the server lets you use the remaining components of MDAC to build your database application.

ActiveX Data Objects (ADO) are a collection of ActiveX components that provide features to retrieve data from OLE DB interfaced databases, manipulate that data, and return data to databases. ADO objects are pre-built and can be called from VBScripts as well as compiled Visual Basic and Visual C++ applications. These objects essentially allow you to rapidly develop the ActiveX based database applications without having to develop the ActiveX components yourself.

Remote Data Service (RDS) is essentially a client side data caching service that allows clients to grab complete sets of data from a server, manipulated them locally, and return them to the server. This obviates network traffic that would be involved with interactive remote manipulation, thereby speeding the process and reducing network bandwidth requirements.

What is the licensing requirement MS SQL Server

What is the licensing requirement MS SQL Server

Licensing requirement MS SQL Server

SQL Server requires a client access license for every concurrent user that attaches to the SQL data source by any means. Therefore, if 1,000 people are accessing your SQL server over the Internet and 200 people are accessing it directly via your in-house LAN, you will need 1,200 client access.

How do you use javascript to return value from SQL Server database

How do you use javascript to return value from SQL Server database

Use javascript to return value from SQL Server database

How do you enable basic authentication in MSSQL and IIS

How do you enable basic authentication in MSSQL and IIS

Enable basic authentication in MSSQL and IIS

Go to Start-> Program-> Microsoft Internet Server-> Internet Service Manager -> Service (tab) ->Password Authentication

In this section select the Basic (clear text) check box. Just click OK to save it.

How do you delete a record in SQL Server

How do you delete a record in SQL Server

Delete a record in SQL Server

In order to delete record (s) from SQL Server use the following codes.

Set conn = Server.CreateObject("ADODB.Connection")

cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"

Set rs = Server.CreateObject("ADODB.Recordset")

SQLstr = "Delete * from employee where EmpID=" & request.form("employeeid")

Rs.open SQLstr, conn, 1,3

How do you search special character in the where clause

How do you search special character in the where clause

Search special character in the where clause

You can do so with the CHR function. As for the correct code, please refer to the ASCII table.

For example let’s say that you want to search for the string "GOD SAVE THE QUEEN"

All you need to do is

Sqlstr = "Select * from song WHERE lyrics =’" & CHR(34) & "GOD SAVE THE QUEEN" & CHR(34) & "’"

Rs.open Sqlstr, conn, 1,3

How do you insert text string into SQL table

How do you insert text string into SQL table

Insert text string into SQL table

If you need to insert the word "Don’t" into SQL Server table, you text have to be formatted as ‘Don’’t’ as the double ‘’ will be interpreted as single embedded quote.

How do you update or modify your data

How do you update or modify your data

Update or modify your data

In order to update your data you can use the following code that utilize the Execute method.

<%

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "DSN=MyDSN"

' Insert a record

conn.Execute("INSERT INTO MyTable(Field1,Field2) VALUES (Value1,

Value2))

' Update a record

conn.Execute("UPDATE MyTable SET Field1 = Value1 WHERE Field1 = Value2")

conn.Close %>

Note that the modification is achieved through the use of SQL statement, which is more efficient.

How do you use ASP to query a ODBC datasource

How do you use ASP to query a ODBC datasource

Use ASP to query a ODBC datasource

<%

if Request("REQUESTTYPE") <> "POST" then

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % If the request does not contain REQUESTTYPE = "POST

' % then display Form Page

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dsn = Session("dsn")

dbuser = Session("dbuser")

dbpass = Session("dbpass")

dbtable = Session("dbtable")

dbfield = Session("dbfield")

dbwhere = Session("dbwhere")

%>

You are authenticated as: <% =

Request.ServerVariables("LOGON_USER")%>

Your IP Address is: <% =

Request.ServerVariables("REMOTE_ADDR")%>

System DSN: ">
Username: ">
Password:

%>">

Table: ">
WHERE
Field to Query: ">
Value to Query: ">


<%

else

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'% Perform Query to Database

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Request the datsource from the Previous Form

' % Set the Session variable so we can retrieve the

' % value for the next query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dsn = Request("datasource")

Session("dsn") = dsn

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Request the username from the Previous Form

' % Set the Session variable so we can retrieve the

' % value for the next query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dbuser = Request("username")

Session("dbuser") = dbuser

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Request the password from the Previous Form

' % Set the Session variable so we can retrieve the

' % value for the next query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dbpass = Request("password")

Session("dbpass") = dbpass

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Request the table from the Previous Form

' % Set the Session variable so we can retrieve the

' % value for the next query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dbtable = Request("table")

Session("dbtable") = dbtable

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Request the table from the Previous Form

' % Set the Session variable so we can retrieve the

' % value for the next query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dbfield = Request("field")

Session("dbfield") = dbfield

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Request the table from the Previous Form

' % Set the Session variable so we can retrieve the

' % value for the next query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dbwhere = Request("where")

Session("dbwhere") = dbwhere

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Check to see if any of the requested values are blank, IF they

' % are, then inform the user which variables are blank ELSE

' % Continue with the query

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if dsn = "" OR dbuser = "" OR dbtable = "" then

Response.write "Error in SQL Statement:
"

if dsn = "" then

Response.write "Missing System DSN

"

end if

if dbuser = "" then

Response.write "Missing Username

"

end if

if dbtable = "" then

Response.write "Missing Tablename

"

end if

Response.write "

VALUE=ReQuery>

"

else

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Create the Conn Object and open it

' % with the supplied parameters

' % System DSN, UserID, Password

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Set Conn = Server.CreateObject("ADODB.Connection")

Set rs = Server.CreateObject("ADODB.RecordSet")

Conn.Open dsn, dbuser, dbpass

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Build the SQL Statement and assign it

' % to the variable sql. Concatinating the dbtable and the SELECT

' % statement

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if dbfield = "" OR dbwhere ="" then

sql="SELECT * FROM " & dbtable

else

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % IF dbfield and dbwhere are specified, then

' % change the SQL statement to use the WHERE clause

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'

sql="SELECT * FROM " & dbtable

sql = sql & " WHERE " & dbfield

sql = sql & " LIKE '%" & dbwhere & "%'"

end if

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % For Debugging, Echo the SQL Statement

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Response.Write "SQL STATEMENT: " &

sql & "


"

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Open the RecordSet (RS) and pass it

' % the connection (conn) and the SQL Statement (sql)

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

RS.Open sql, Conn

%>

<%

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Loop through Fields Names and print out the Field Names

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

For i = 0 to RS.Fields.Count - 1

%>

<% Next %>

<%

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Loop through rows, displaying each field

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Do While Not RS.EOF

%>

<% For i = 0 to RS.Fields.Count - 1 %>

<% Next %>

<%

RS.MoveNext

Loop

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

' % Make sure to close the Result Set and the Connection object

' %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

RS.Close

Conn.Close

%>

<% = RS(i).Name %>
<% = RS(i) %>

<%

end if

end if

%>

How to determined the number of parameter in a stored procedures

How to determined the number of parameter in a stored procedures

To determined the number of parameter in a stored procedures

Here’s the code to display the stored procedure called sp_MyStoredProc.

<%@ LANGUAGE = VBScript %>

Stored Proc Example

<%

Set Conn = Server.CreateObject("ADODB.Connection")

' The following line must be changed to reflect your data source info

Conn.Open "data source name", "user id", "password"

set cmd = Server.CreateObject("ADODB.Command")

set cmd.ActiveConnection = Conn

' Specify the name of the stored procedure you wish to call

cmd.CommandText = "sp_MyStoredProc"

cmd.CommandType = adCmdStoredProc

' Query the server for what the parameters are

cmd.Parameters.Refresh

%>

<% For Each param In cmd.Parameters %>

<%

Next

Conn.Close

%>

PARAMETER NAME DATA-TYPE DIRECTION DATA-SIZE
<%= param.name %> <%= param.type %> <%= param.direction %> <%= param.size %>

An example of output might look like this

PARAMETER NAME DATA-TYPE DIRECTION DATA-SIZE

Return_Value 3 4 0

param1 129 1 30

Please note that without including the adovbs.inc you are not able to use the constanst such as these.

'---- ParameterDirectionEnum Values ----

Const adParamInput = &H0001

Const adParamReturnValue = &H0004

'---- DataTypeEnum Values ----

Const adInteger = 3

Const adChar = 129

But you can use the numeric value associated with it.

How do access SQL Server from Integrated Security from ASP

How do access SQL Server from Integrated Security from ASP

Access SQL Server from Integrated Security from ASP

In order to do this, you would have to setup your DSN to point the server parameter to the local machine instead of looking for MSSQL Server.

This can be done by setting up your DSN and then under the server.

After that, select the How should SQL Server verify the authenticity of the login ID select With NT Authentication using the network login id.


Can you use begin transaction or rollback in ASP with SQL Server

Can you use begin transaction or rollback in ASP with SQL Server

Use begin transaction or rollback in ASP with SQL Server

Yes, you can do that. This in not only limited to SQL Server, Access supports this as well.

How efficient is the method shown above

How efficient is the method shown above

How efficient is the method shown above

Well, this is not really efficient because you are opening the entire table to the recordset and then finally you add your record in. It can be done but rather unnecessary.

The more efficient way of doing it would be

Set conn = Server.CreateObject("ADODB.Connection")

cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"

Set rs = Server.CreateObject("ADODB.Recordset")

Rs.open "INSERT INTO EMPLOYEE(name, position) VALUES (‘Alan’, ‘

Sales Manager’), conn, 1,3

Adding new records into SQL Server

Adding new records into SQL Server

Adding new records into SQL Server

New records (not blobs) can be added using the AddNew function.

Here’s the code to insert a new code into the MSSQL database.

Set conn = Server.CreateObject("ADODB.Connection")

cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"

Set rs = Server.CreateObject("ADODB.Recordset")

Rs.open "Employee", conn, 1,3

Rs.addnew

Rs("name") = request.form("empname")

Rs("position") = request.form("position")

Rs.update

Rs.close

How do display our result out from SQL Server

How do display our result out from SQL Server

Display our result out from SQL Server

The method used to display data from a search query is the same as the method employed in Access database.

Set conn = Server.CreateObject("ADODB.Connection")

cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"

Set rs = Server.CreateObject("ADODB.Recordset")

Rs.open "Select * from employee", conn, 1,3

‘ we’re constructing a loop to display all the data out

do while rs.eof <> true

response.write(rs("name"))

response.write("
")

response.write(rs("position"))

rs.movenext

loop

How do you display images stored in BLOBS

How do you display images stored in BLOBS

Display images stored in BLOBS

Type in the following codes and run it.

<%

' 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 %>

How do you make your stored procedure run faster

How do you make your stored procedure run faster

Make your stored procedure run faster

Microsoft recommends that you should use the CreateParameter in your scripts.

CREATE PROCEDURE ProductInfo1

@ProductID int

AS

SELECT p.ProductName,

c.CategoryName, s.CompanyName,

p.UnitPrice

FROM Products p INNER JOIN Suppliers s ON

p.SupplierID = s.SupplierID

INNER JOIN Categories c ON

p.CategoryID = c.CategoryID

WHERE p.ProductID=@ProductID

Referring to the stored procedure above but this time we’re going to test it out with our ASP here.

set cn=server.CreateObject("ADODB.connection")

set cmd=server.CreateObject("ADODB.command")

set pProductID= _

cmd.CreateParameter("ProductID",adInteger, _

adParamInput)

set pProductName= _

cmd.CreateParameter("ProductName",adVarChar, _

adParamOutput,40)

set pCompanyName= _

cmd.CreateParameter("CompanyName",adVarChar, _

adParamOutput,40)

set pCategoryName= _

cmd.CreateParameter("CategoryName",adVarChar, _

adParamOutput,15)

set pUnitPrice= _

cmd.CreateParameter("UnitPrice",adCurrency, _

adParamOutput)

cn.Open "Provider=SQLOLEDB.1;Password=;User ID=sa;" & _

"Initial Catalog=Northwind;Data Source=laptop"

set cmd.ActiveConnection=cn

cmd.CommandText="ProductInfo2"

cmd.Parameters.Append pProductID

cmd.Parameters.Append pProductName

cmd.Parameters.Append pCompanyName

cmd.Parameters.Append pCategoryName

cmd.Parameters.Append pUnitPrice

How do you call a MSSQL stored procedure from ASP

How do you call a MSSQL stored procedure from ASP

Call a MSSQL stored procedure from ASP

And here’s the ASP code to call it.

<%

Set cn = Server.CreateObject("ADODB.Connection")

Set cmd = Server.CreateObject("ADODB.Command")

cn.Open "data source name", "userid", "password"

Set cmd.ActiveConnection = cn

cmd.CommandText = "sp_test"

cmd.CommandType = adCmdStoredProc

' Ask the server about the parameters for the stored proc

cmd.Parameters.Refresh

' Assign a value to the 2nd parameter.

' Index of 0 represents first parameter.

cmd.Parameters(1) = 11

cmd.Execute

%>

How do you use Global.asa to access your SQLServer

How do you use Global.asa to access your SQLServer

Use Global.asa to access your SQLServer

Here’s an example of codes that will allow you to do so

<% Set OBJdbConnection = Server.CreateObject("ADODB.Connection")

OBJdbConnection.ConnectionTimeout = Session("ConnectionTimeout")

OBJdbConnection.CommandTimeout = Session("CommandTimeout")

OBJdbConnection.Open Session("ConnectionString")

Set SQLStmt = Server.CreateObject("ADODB.Command")

Set RS = Server.CreateObject ("ADODB.Recordset")

%>

<%

SQLStmt.CommandText = "select * from authors"

SQLStmt.CommandType = 1

Set SQLStmt.ActiveConnection = OBJdbConnection

RS.Open SQLStmt

What is the use of Global.asa

What is the use of Global.asa

The use of Globalasa

Global.asa serves as important configuration information for running ASP in a virtual directory within IIS. For example code for accessing SQL Server might be kept in the following files as

Sub Session_OnStart

Session("ConnectionString") =

"DSN=SQLSysDSN;UID=sa;PWD=;DATABASE=pubs;APP=ASP script"

Session("ConnectionTimeout") = 15

Session("CommandTimeout") = 30

End Sub

How to use ASP to redirect failed ADO connection to a backup SQL server

How to use ASP to redirect failed ADO connection to a backup SQL server

Use ASP to redirect failed ADO connection to a backup SQL server

on error resume next

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open MSCSSite.DefaultConnectionString

Set cmdTemp = Server.CreateObject("ADODB.Command")

cmdTemp.CommandType = adCmdText

Set cmdTemp.ActiveConnection = conn

' If the above ADO connection fails, then we check

' the error number, if it is not equal to 0, then we change

' the MSCSSite.DefaultConnectionString to one of the

' connection strings in the mscssite.connectionstringmap.

' For purposes of this example, the default database is

' SSCommerce and the backup is SSCommerce2

If Err.Number <> 0 Then

err.clear

mscssite.defaultconnectionstring = mcssite.connectionstringmap("SSCommerce2")

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open MSCSSite.DefaultConnectionString

Set cmdTemp = Server.CreateObject("ADODB.Command")

cmdTemp.CommandType = adCmdText

Set cmdTemp.ActiveConnection = conn

End if

How to setup a connection to a backup SQL server for ASP redirection

How to setup a connection to a backup SQL server for ASP redirection

Setup a connection to a backup SQL server for ASP redirection

Go to Commerce Host Administration in MMC and then add a database connection.

- Click on Store and select properties

- Select database connection

- Under connection Map, click Add

How to use ASP to issue the SELECT statement to SQL Server

How to use ASP to issue the SELECT statement to SQL Server

Use ASP to issue the SELECT statement to SQL Server

You need to create a ADO recordset and then open the recordset using the open statement with the SQL statement in it.

This is an example of how you should do it.

Set rs = Server.CreateObject("ADODB.Recordset") ‘ creates the recordset

Sqlstr = "SELECT * from employee"

rs.open Sqlstr, conn, 1,3


What is the ODBC 80004005 Error

What is the ODBC 80004005 Error

ODBC 80004005 Error

If you encounter this problem that means that there’s a problem in connecting to your database. Try using a local named pipe connection instead of a network named pipe connection if SQL Server is running on the same computer as IIS. Windows 2000 security rules will not be enforced because the pipe is a local connection rather than a network connection. There is a problem with access SQL Server through the TCP/IP method, so we recommend that you use DSN.


How to connect to the Analysis Server through the use of URL

How to connect to the Analysis Server through the use of URL

Connect to the Analysis Server through the use of URL

Here’s how the code does it.

Dim cat as new ADOMD.Catalog

cat.ActiveConnection = "Provider = msolap;" & _

" Datasource =" _ &

" http://www.microsoft.com/;" & _

" Initial Catalog = FoodMart 2000"

How do you access the database through OLEDB

How do you access the database through OLEDB

Access the database through OLEDB

<%

set conn=Server.CreateObject("ADODB.Connection")

conn = "Provider=SQLOLEDB.1; Data Source=C:\inetpub\wwwroot\crm\testData.MDF; Driver={SQL Server};Server=Jaguar "

set rs=Server.CreateObject("ADODB.Recordset")

rs.open "select * from allrecord", conn, 1,3

do while rs.eof <> true

response.write(rs("email"))

response.write("
")

rs.movenext

loop

%>

What is the difference between OLE DB and ODBC

What is the difference between OLE DB and ODBC

Difference between OLE DB and ODBC

OLE DB provides a more efficient means of accessing the database as compared to ODBC. OLE DB is a system-level programming interface that provides standard set of COM interfaces for exposing database management system functionality.

How do you use ASP access SQL Server through DNS(ODBC)

How do you use ASP access SQL Server through DNS(ODBC)

Use ASP access SQL Server through DNS(ODBC)

<%

set conn=Server.CreateObject("ADODB.Connection")

conn.Open "DSN=tenderproject;UID=tenderproject;PWD=tender"

set rs=Server.CreateObject("ADODB.Recordset")

%>

Server.CreateObject("ADODB.connection") it is use initiated a connection to your SQL Server database.

In this case we are using a data source name called Tenderproject. We also provide a UserID (UID=tenderproject) and password (PWD=tender) as shown in the coding above.

How do you setup your DNS in your Window NT

How do you setup your DNS in your Window NT

Setup your DNS in your Window NT

Go to Control Panel->ODBC Data Sources->DSN

After that, click on Add. The following screen will appear.

Once you have selected SQL Server, and then proceed to click Finish.

Having done that, another dialog box will appear prompting you for your user id and password

Click Next to continue

Select the appropriate option suitable for you and then click Next to continue.

Again, select the option suitable for you. Click Next to proceed to the next phase.

Now you have completed the setting up of your DSN.


How do you activate SQL Server DTS packages from ASP

How do you activate SQL Server DTS packages from ASP

Activate SQL Server DTS packages from ASP

All you have to do is to

Create an instance of DTS package using Server.CreateObject("DTS.package")

And load it using LoadFromSQLServer

Here’s an example of the code to do it. You need to make sure that you have created a DTS package first.

Dim oPkg, oStep, sMessage, bStatus

Set oPkg = Server.CreateObject("DTS.Package")

oPkg.LoadFromSQLServer "MyServer","MyUser","MyPassword",DTSSQLStgFlag_Default,"PackagePassword","","","MyPackage"

oPkg.Execute()

bStatus = True

For Each oStep In oPkg.Steps

sMessage = sMessage & "

Step [" & oStep.Name & "] "

If oStep.ExecutionResult = DTSStepExecResult_Failure Then

sMessage = sMessage & " failed
"

bStatus = False

Else

sMessage = sMessage & " succeeded
"

End If

sMessage = sMessage & "Task """ & oPkg.Tasks(oStep.TaskName).Description & """

"

Next

If bStatus Then

sMessage = sMessage & "

Package [" & oPkg.Name & "] succeeded

"

Else

sMessage = sMessage & "

Package [" & oPkg.Name & "] failed

"

End If

Response.Write sMessage

Response.Write "

Done

"

%>

Why use SQL Server in ASP scripting

Why use SQL Server in ASP scripting

SQL Server in ASP scripting

SQL Server represents the medium to high-end range of database management system. This means that it offers large and extensible disk space, more functionality and most of all flexible.