Forums
This topic is locked
Example:storing the DB connection string in a DLL!
Posted 05 Mar 2006 23:53:52
1
has voted
05 Mar 2006 23:53:52 Raafat Abdul posted:
This example illustrates how to write a DLL file in VB6 and storing (hiding) the database connection string inside it and calling it from an ASP.Q) So why do we need to hide the connection string anyway?
A) Your connection string contains valuable information; the username and password to your database and in some cases, you don't want that information to fall in the wrong hands. For example: If you are writing a web application in Dreamweaver, and if anyone has access to the server, they can look inside the directory called "Connections" and they can open the ASP page inside it and simply get all the information to your database.
To make sensitive information harder to get, we can place it in a DLL file and simply call it from the pages.
<b>Part 1: Creating a COM ActiveX DLL in VB6</b>
We will write a simple function to return our connection string when calling it.
1- Run Microsoft Visual Basic to create a new project.
2- From the New Project window, double click on ActiveX DLL.
3- From the top menu, click on PROJECT > PROJECT PROPERTIES and in the project name field, enter "myConnectionString" and click OK.
4- We now want to change the names or references on the class object. Click on the Class1 module. In the properties box and in the name section, enter "classCon"
5- in the code section, past the bellow function and change the connection string to reflect to your connection string:
<b>Function ConnectionFunction()
' do not forget to change the string to your database connection string
' The next 2 lines must be on a one line
ConnectionFunction = "Provider=OraOLEDB.Oracle.1;Password=123456;Persist Security Info=True;User ID=DBO;Data Source=maindb"
End Function
</b>
6- We need now to compile the DLL. From the File menu choose "Make myConnectionString.dll". Save the DLL in a directory of your choice.
7- We need to register our DLL file on our machine. Open the MS-DOS command line window
and change the directory to where you saved the dll. Now type the following:
regsvr32 myConnectionString.dll
you will get a conformation window with successful registration…. we are done!
<b>Part 2: Calling the DLL from the ASPs</b>
1- Create a new ASP JavaScript page like you normally do.
2- Create a custom Connection String from the Database section and enter "DBConnection" in the connection name and your connection string in the connection string fields. Test your connection.
3- Create a Recordset .
4- Create a Dynamic Table on your page and bind it to the Recordset.
5- Save the page and test it.
6- Open to edit the file "DBConnection.asp" located in the Connections directory and change everything to:
<b>
<%
var myConString;
var myConString =Server.CreateObject("myConnectionString.classCon"
MM_DBConnection_STRING= myConString.ConnectionFunction();
%>
</b>
7- Save and run the page.
Replies
Replied 11 Aug 2006 01:08:04
11 Aug 2006 01:08:04 Suki Chui replied:
I followed the instructions as what you provided; however, it generate an error messpage ,"The page cannot be displayed." May I ask why? is it because of the permission issue? <img src=../images/dmxzone/forum/icon_smile_blackeye.gif border=0 align=middle><img src=../images/dmxzone/forum/icon_smile_blackeye.gif border=0 align=middle>