Total members 11889 |It is currently Sun Apr 14, 2024 10:17 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





MYSQL is a very popular database management system for web applications. In this small article we show how to start a connection to MYSQL via ASP script. In this example we establish our connection in a separate file we named it “myconnection.asp” and this file will be included in your main asp page. The reasons for separating the connections file are “usability” and easy maintenance. In your asp page you will include the connection file:
<!-- #include virtual = "/ myconnection.asp" -->
The content myconnection.asp:
Code:
<% Dim connInfo
connInfo 
= "Provider=SQLOLEDB;Data " _
& "Source=source_name;Database=databaseName;" _
& "UID=Username; PWD=Password;"
%>


This is ASP (Active Server Pages) code that creates a variable named "connInfo" which contains a string that represents a connection string to a SQL Server database. The connection string is composed of several parts separated by semicolons (;), each part represents a different aspect of the connection to the database.
    "Provider=SQLOLEDB" specifies the OLE DB provider to use to connect to the database, in this case, it's SQLOLEDB.
    "Data Source=source_name" specifies the name or IP address of the server where the database is located.
    "Database=databaseName" specifies the name of the database to connect to.
    "UID=Username" specifies the username to use when connecting to the database.
    "PWD=Password" specifies the password to use when connecting to the database.
This connection string is a standard format, it can be used by different libraries and objects to connect to the database, such as ADODB, ADO.NET and other libraries.

It's important to note that this code snippet is only creating a variable that contains the connection string information, it is not opening a connection to the database. Also, it's important to note that the connection string contains the username and password in plain text. It's recommended to use other ways to store this information more securely. It's also essential to ensure that the connection string contains the correct information to connect to the database. Also, the database should be configured to allow remote connections if the script is running on a different server.



In addition, it's worth noting that there are other ways to specify the connection string; for example, it can be stored in a separate file or in the web.config file, this allows for easier management of the connection string and makes it more secure as the connection string is not hardcoded in the script. It's also worth noting that there are other options that can be specified in the connection string, depending on the provider and the database. For example, it's possible to specify the protocol to use to connect to the database, the timeout for the connection, the options for encrypting the connection, and so on. It's also important to note that, depending on the environment, there are other ways to store the connection string. For example, it's possible to use the Windows Data Protection API (DPAPI) to encrypt the connection string in a Windows environment. The connection string can be passed as an environment variable in a containerized environment. It's also important to note that, depending on the database and the provider, other options may be required, for example, if the database is using integrated security or if you need to specify the trusted connection. It's essential to check the documentation for the provider and database you are connecting to for a complete list of connection string options and how to use them.



Now we use the string in our asp application page
Code:
<%@ Language=VBScript %>
 
<!-- #include virtual = "/adovbs.inc" -->
<!-- #include virtual = "/ myconnection.asp" -->

<!doctype html public "-//w3c//dtd html 3.2//en">

<
html>

<
head>
<
title>Applicationspage</title>
</
head>

<
body>
<%
Dim myconnection,R,SQL,RecsAffected

Set myconnection 
=Server.CreateObject("ADODB.Connection")
myconnection.Mode=adModeReadWrite
myconnection
.ConnectionString = connInfo
myconnection
.Open




If your application failed to start a connection you will get error :
Code:
Microsoft OLE DB Provider for SQL Server (0x80004005)
[
DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.




Using a connection pooling mechanism when connecting to a database is good practice, especially when the application is expected to handle many connections. Connection pooling allows for reusing existing connections instead of creating new ones for each request, thus reducing the overhead of creating and closing connections. This can improve the application's performance and reduce the load on the database server. It's also worth noting that, depending on the database and the provider, there may be different ways to enable connection pooling. For example, in the case of SQL Server and the SQLOLEDB provider, connection pooling is enabled by default, but other databases and providers may require specific configuration. It's also worth mentioning that it's essential to test the application with different load and concurrency scenarios to ensure that the connection pooling is configured correctly and that the application can handle the expected number of connections without running out of resources. It's also important to note that, depending on the database and the provider, the connection pooling can be managed programmatically using the methods provided by the provider, for example, using the OLE DB Services Component to set the pooling options. In summary, it's essential to consider how the connection string is being stored and the options for connection pooling when connecting to a database to improve performance and reduce the load on the database server.



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : connect to MYSQL from ASP
 How to Connect to MySql Server     -  
 How to connect two computers and connect them with Internet?     -  
 Connect Dots     -  
 HELP CONNECT SQL SERVER 2005 WITH PHP 5.2.6     -  
 How to connect database with Applets     -  
 how to connect applet with excel     -  
 connect SSIS package with ASP.net     -  
 How do I connect my form tomy database     -  
 How to connect to serial port using java     -  
 clients cannot connect to server on another machine     -  



Topic Tags

ASP MYSQL
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com