Link to home
Start Free TrialLog in
Avatar of MikeHall12
MikeHall12

asked on

1 ASP page implementation in production server.Should I need to create project or tell me procedures

I have an asp page, I want to implement to production server,Should I have to create a interdev project to run this asp page when user request
the link is now like this, i created a asp page in existing application
http://localhost.nicor.com/TCI/Testing.asp?
the asp page is connecting to access database. Right now i have physical path listed for connecting datasource. Can we connect to network drive instead.
Sub OpenDB
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Request.ServerVariables("APPL_PHYSICAL_PATH") & "\MeterCheck\Meter.mdb"
End Sub
Please help me with the suggestions and code for datasource connecting to "U:\Metertrack\Meters.mdb"
I'll appreciate any help for this
Thanks
Mike
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

You shouldn't have to create an interdev project at all. The main thing is just to get the path.

I would try this:

<%
strPath = Request.ServerVariables("APPL_PHYSICAL_PATH")  & "Meters.mdb"
response.write strPath
response.end
%>

Alternatively, you could just try this:

strPath  = Server.MapPath("Meters.mdb")
response.write strPath
response.end

Fritz the Blank
Helloo

Yes you can use a network path to store your mdb file provided that folder has read write access to the IUSER windows user..

Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="u:\MeterCheck\Meter.mdb"

neeraj523
Avatar of MikeHall12
MikeHall12

ASKER

Neeraj,
If I use your statement for obj connection.
I am getting Expected end of statement error.
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="u:\Phonebk\Meter.mdb"
Please let me know, What we are missing here.
Please help me...
It is very urget for me.
Thanks
Mike
It worked with U:Drive connecting.
No problem
Should I have to create a project to load the asp form in users machine

How will I implement the asp page
Oh, you don't load it on the user's machine, but rather on a server running IIS, or at the very least, a computer running PWS.

Fritz the Blank
So server has to have the rights to connect to particular folder to read, insert to database.
How that works, can you explain please ...
My local machine is working, How will I implement in production server.
Once you move the project to the production server, you will need to set up IIS to host your new page (site). The user will then type the address into the address bar, the server will serve up the page, and all should be well.

In order for things to work on the server, the IUSR account must have READ/WRITE access to the folder that houses the database.

Fritz the Blank
Fritz,\Please help me ,
Now I asked Administrator to give access to development server IUSR_MALAMUTE, Admin gave access to MALMUTE server.
And I am still getting message
Microsoft JET Database Engine (0x80004005)
'U:\Meter Track\Meter.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
/MeterTracking/Metertracking.asp, line 331

I tried in local with my user Id access, it worked fine,
Does this account has to be in active directory to give access to Network drive.

Please email me with suggestions
THanksMike
I am not sure what is going on here exactly.

What is the directory that your pages are in?
Where is the database?

Fritz the Blank
This is the code, i have to to insert the values entered by user to Network U:drive
Local is working fine. In development Not, Does development has to have Access installed or it should have active directory to connect to U:drive(Network drive). Admin gave rights to development server to access to networjk drive. itr does not work.

please help me how to resolve this matter.
'-----------------------------------------------------------------------------------
<%@ Language=VBScript %>
<%Option Explicit%>
<%

'Function / Sub Variables
Dim objCon            'Used for database connection
Dim sTempStr      'Temporary variable to hold the date values
Dim sTmpStr            'Temporary variable to hold the date values
Dim iTempVal      'Temporary variable to
Dim iTmpVal

'Page Variables
Dim sForm(2)
Dim sData(9,1)
Dim sErrMsg
Dim sQuery
Dim iLp
Dim iLoop
Dim bIsMeter
Dim sRegions
Dim rsRegions

'Database connection call
OpenDB
'get regions from database for regions dropdown
sRegions = "SELECT REGION FROM REGION"
Set rsRegions = objcon.Execute(sRegions)


'Load IN/OUT Deafult
For iLp = 0 to 9
      sData(iLp,1) = "OUT"
Next

'Get Passed Back Form Data After INSERT
If CBool(Request.QueryString("pass")) = True then
      sForm(0) = Request.QueryString("empid")
      sForm(1) = Request.QueryString("date")
      sForm(2) = Request.QueryString("reg")
End If

'Form Has Been Submitted
If Request.Form("Action") = "Add" then
      sErrMsg = ""

            'Collect Up The General Info
            For iLp = 0 to 2
                  sForm(iLp) = Trim(Request.Form("f_"&iLp))
            Next

            'Collect Up The Meter Info
            For iLp = 0 to 9
                  For iLoop = 0 to 1
                        sData(iLp,iLoop) = Trim(Request.Form("m_"&iLoop&"_"&iLp))
                  Next
            Next

      'Validation of form with proper values
      If sErrMsg = "" then
            'validation for Employee ID
            If (sForm(0) = "") or (sForm(0) = "99999") or not (IsNumeric(sForm(0)))or (Len(sForm(0)) <> 5) then
                        If sForm(0) = "" then
                              sErrMsg = "Error: Employee ID - Required field."
                        Elseif sForm(0) = "99999" or not IsNumeric(sForm(0))or (Len(sForm(0)) <> 5) then
                        sErrMsg = "Error: Employee ID - Invalid Value."
                        End If
                  Else
            
                        'validation for Date
                        If sForm(1) = "" then
                              sErrMsg = "Error: Date - Required Field."
                        Else
                              sForm(1) = PadDate(sForm(1))
                              If ValidateDate(sForm(1),sErrMsg) = True then
                                    sForm(1) = sErrMsg
                                    sErrMsg = ""
            
                                    'validation for Region
                                    If sForm(2) = "" then
                                          sErrMsg = "Error: Region - Required Field."
                                    Else
                                    sForm(2) = SetCap(sForm(2))

                                    'validation for Meter Info
                                    bIsMeter = False
                                    'If meter details yes, check for valid Meter info
                                    For iLp = 0 to 9
                                         If sData(iLp,0) <> "" then
                                              If Left(sData(iLp,0),1) = "7" then
                                                   sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Can't Start With 7."
                                              Else
                                                   If Len(sData(iLp,0)) <> 7 then
                                                        sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Wrong Length."
                                                   Else
                                                        bIsMeter = True
                                                   End If
                                              End If
                                                                       
                                              If sErrMsg <> "" then
                                                   iLp = 9
                                              End If
                                         End If
                                    Next

                                          'Checking for Meter Details
                                          If sErrMsg = "" then
                                          'All Ok - INSERT Details into DB
                                                If bIsMeter = False then
                                                      sErrMsg = "Error: Meter No Details - Required."
                                                Else
                                                      If sErrMsg = "" then
                                                            For iLp = 0 to 9
                                                                  If sData(iLp,0) <> "" then
                                                                        sQuery = "INSERT INTO GasMeterTrack (EmployeeID, MeterDate, Region, MeterSerialNo, Status) VALUES " &_
                                                                        "('" & SQL(sForm(0)) & "','" & sForm(1) & "','" & SQL(sForm(2)) & "'," &_
                                                                        "'" & SQL(sData(iLp,0)) & "','" & sData(iLp,1) & "')"
                                                                        objCon.Execute sQuery
                                                                  End If
                                                            Next

                                                            Response.Redirect "MeterTracking.asp?pass=True&empid=" & sForm(0) & "&date=" & sForm(1) & "&reg=" & sForm(2)
                                                      End If
                                                End If
                                          End If
                                    End If
                              End If
                        End If
            End If
      End If
End If

CloseDB
%>
<html>
      <head>
            <title>Meter Information</title>
      </head>
<body>
      <table width="500" cellspacing="1" cellpadding="0" border="0" bgcolor="#000000" align=center>
            <form name="Reading" method="post" action="MeterTracking.asp">
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30"><b>M E T E R&nbsp;&nbsp;&nbsp;I N F O R M A T I O N</b></td>
                                    </tr>
                              </table>
                  <td>
                  </tr>
                  <%If sErrMsg <> "" then%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30"><font color="#FF0000"><%=sErrMsg%></font>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <%End If%>
                  <%If CBool(Request.QueryString("pass")) = True then%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30">Notice: Info Successfully inserted into DB.
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <%End If%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td colspan="2" height="30"><b>General Details:</b></td>
                                    </tr>
                                    <tr>
                                          <td width="100" height="25">*Employee ID:
                                          </td>
                                          <td width="400">
                                                <input type="text" name="f_0" size="5" maxlength="5" value="<%=sForm(0)%>">
                                          </td>
                                    </tr>
                                    <tr>
                                          <td height="25">*Date:
                                          </td>
                                          <td>
                                                <input type="text" name="f_1" size="10" maxlength="10" value="<%=sForm(1)%>">(Ex-01/01/2004)
                                          </td>
                                    </tr>
                                    <tr>
                                          <td height="25">*Region:
                                          </td>
                                          <td>
                                                <!--<input type="text" name="f_2" size="25" maxlength="25" value="<%=sForm(2)%>">-->
                                          <select name="f_2">
                                             <%If sForm(2) = "" then%>
                                                      <option value="">Please select</option>
                                             <%End If
                                             Do while not rsRegions.EOF
                                                If sForm(2) = rsRegions("Region") then%>
                                                   <option value="<%=rsRegions("Region")%>" selected><%=rsRegions("Region")%></option>
                                                <%Else%>
                                                   <option value="<%=rsRegions("Region")%>"><%=rsRegions("Region")%></option>
                                                <%End If
                                                rsRegions.MoveNext
                                             Loop%>
                                          </select>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td colspan="4" height="30"><b>Meter Numbers:</b>
                                          </td>
                                    </tr>
                                    <%For iLp = 0 to 9%>
                                    <tr>
                                          <td width="100" height="25">Meter No:
                                          </td>
                                          <td width="125">
                                                <input type="text" name="m_0_<%=iLp%>" size="6" maxlength="7" value="<%=sData(iLp,0)%>"">(7 Digits)
                                          </td>
                                          <td width="50">Status:
                                          </td>
                                          <td width="225">
                                                <input type="radio" name="m_1_<%=iLp%>" value="OUT" <%If sData(iLp,1) = "OUT" then%>checked<%End If%>>&nbsp;OUT&nbsp;&nbsp;
                                                <input type="radio" name="m_1_<%=iLp%>" value="IN" <%If sData(iLp,1) = "IN" then%>checked<%End If%>>&nbsp;IN
                                          </td>
                                    </tr>
                                    <%Next%>
                              </table>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30" align="center">
                                                <input type="hidden" name="Action" value="Add">
                                                <input type="submit" name="Button" value="Submit">
                                                <input id=reset name=reset type=reset value=Reset></TD>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
            </form>
      </table>
</body>
</html>
<%
'Function for Date value
Function PadDate(Value)
If Len(Value) = 0 then
      PadDate = Value
Else
      If IsDate(Value) then
            sTmpStr = ""
            sTempStr = ""
            iTempVal = 0
            For iLp = 1 to Len(Value)
                  If IsNumeric(Mid(Value,iLp,1)) then
                        sTempStr = sTempStr & Mid(Value,iLp,1)
                  Else
                  If Len(sTempStr) > 2 then
                        PadDate = Value
                  Else
                        sTempStr = Left("00",2-Len(sTempStr)) & sTempStr & "/"
                        sTmpStr = sTmpStr & sTempStr
                        sTempStr = ""
                  End If
                  End If
            Next
                  If Len(sTempStr) > 4 then
                        PadDate = Value
                  Else
                        PadDate = sTmpStr & Left("2000",4-Len(sTempStr)) & sTempStr
                  End If
      Else
            PadDate = Value
      End If
End If
End Function

'Function for validating Date value entered by user
Function ValidateDate(Value, sErrMsg)
If Len(Value) <> 10 then
      ValidateDate = False
      sErrMsg = "Error: Date - Invalid."
Else
      If IsNumeric(Mid(Value,1,2)) and IsNumeric(Mid(Value,4,2)) and IsNumeric(Mid(Value,7,4)) then
            Value = Mid(Value,1,2) & "/" & Mid(Value,4,2) & "/" & Mid(Value,7,4)
            If IsDate(Value) then
                  ValidateDate = True
                  sErrMsg = Value
            Else
                  ValidateDate = False
                  sErrMsg = "Error: Date - Invalid."
            End If
      Else
            ValidateDate = False
            sErrMsg = "Error: Date - Invalid."
      End If
End If
End Function

'Opening Database connection
Sub OpenDB
'Set objCon = Server.CreateObject("ADODB.Connection")
'objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Request.ServerVariables("APPL_PHYSICAL_PATH") & "\MeterCheck\Meter.mdb"
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=U:\Meter Track\Meter.mdb"
'objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Temp\Meter.mdb"
End Sub

'Closing Database connection
Sub CloseDB
Set objCon = Nothing
End Sub

'Function to replace quotes
Function SQL(Value)
SQL = Replace(Value,"'","''")
End Function

'Function used for capitilizing the values
Function SetCap(Value)
If Value <> "" Then
      sTempStr = ""
      sTempStr = sTempStr & UCase(Mid(Value, 1, 1))
      For iTempval = 2 To Len(Value)
            If Mid(Value, iTempval-1, 1) = " " Then
                  sTempStr = sTempStr & UCase(Mid(Value, iTempval, 1))
            Else
            sTempStr = sTempStr + Mid(Value, iTempval, 1)
            End If
      Next
      SetCap = sTempStr
End If
End Function

%>

'--------------------------------------------------------------------------
I'll appreciate your help
Thanks
Mike
The database is located in Network drive, so the datasource is
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=U:\Meter Track\Meter.mdb"

Localhost connecting to U:drive in my machine is working fine.
Admin also gave rights to development server to access to U:drive\Meter Track
Then also, i am getting message
Microsoft JET Database Engine (0x80004005)
'U:\Meter Track\Meter.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
/MeterTracking/MeterTracking.asp, line 331

This is because, It cannot work on this folder with no active directory setup for server account or anything else?
Please help me
Mike
Okay, so the problem is here, is it?

objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="u:\Phonebk\Meter.mdb"

You might try this:


objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="\\Phonebk\Meter.mdb"


Fritz the Blank
I tried with this path Fritz
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="\\Phonebk\Meter.mdb"

I am getting Not a valid file name
Error Type:
Microsoft JET Database Engine (0x80004005)
Not a valid file name.
/MeterTracking/MeterTracking.asp, line 332

Please help me.
You had quotes in between the so tried
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source="\\Phonebk\Meter.mdb""
I got message syntax error
Then I changed to take away quotes.
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=\\Phonebk\Meter.mdb"

Doe it matter with the quotes for location
Thanks
Mike
Sorry, that was a typo on my part...

I meant to write:

objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=\\Phonebk\Meter.mdb"


Fritz the Blank
Please help me Fritz,
It is extremely urget, I have to implement this application inproduction tomorrow.
Any help is apprecited.

What Should I change in the code, to work on this application properly.

Please...
Mike
Is there no way that the database can reside on the same server as your web application?

Fritz the Blank
No because supervisors will go to Network drive(U/Phonebk/Meter.mdb to see the data entered by field employees.

Suggest me if we can solve this with another option. I can change the requirement and communicate to client.
If it is not possible with this network drive access.

Thanks
for your response
Mike
Mike, I know that this can be done, and I have done it before, it is just I am not there, so it is difficult to work through it.

Please see the very last comment in this thread:

https://www.experts-exchange.com/questions/20333178/Unable-to-use-mapped-network-drive-in-ADO-connection-string.html?query=mapped+drives+connection&searchType=topic


Fritz the Blank
I did attempted to map to network drive in windows explorer, It worked mnapping,but when I use the path in the datasource, it is not connecting, i am getting message
Error Type:
Microsoft JET Database Engine (0x80004005)
'C:\WINNT\system32\Meter Track on 'Nigasfs\Coshare'\Meter.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
/MeterTracking/MeterTracking.asp, line 332


Thanks
Mike
Are you talking about a share to your client machine or a share to the server?

You need the latter; the former will not work.

FtB
The network drive name is "Coshare on 'Nigasfs'". So is it not possible to connect to this drive in development server.
I my machine I have set up called Coshare on 'Nigasfs' (U:), and I have no problem connecting to this drive.

Please tell me wheather we can do this or not?

ThanksMike
But the .asp page runs on the server, so the share has to be on that server, not on your machine....

FtB
So share canot be on the server?can you please give me alternate solution for this FTB

I am very desperate now. Please provide me with the alternate solution.
I have to do this by today.
Otherwise i am in deep problem.
Mike--

Let's make sure I understand. You have a web server. Your access database is somewhere else. You have a share on your webserver to that other location, is that correct? When you use the explorer on the web server, you can actually see the mapped drive?

FtB

Yes it is correct

Yes, I see the mapped drive
An the map drive looks like this
Meter Track on 'Nigasfs\Coshare' on the windows Explorer.
Please Tell me what to put in the Datasource path
And access is not installed on web server.
So file is looking like text file. will it be a problem?
I can only open with Notepad. Meter.mdb, It says MDB file.
You won't need Access on the server, so you should be fine.


objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=\\Nigasfs\Coshare\Meter.mdb"

FtB
Mike--

Unfortunately, I have to leave for the night.

Best of luck to you,

FtB
Can you help me tommorrow, please.
Thanks
a lot for your help today
Mike
Goodnight

Helloo Mike

I am surprised, still you are not able to solve your issue.. I feel mdb on a mapped path should work for a asp connection.. really don't know whats wrong at ur end...

I have on alternative which might work for you.. Why don't you shift your web folder to the network path where your mdb is residing.. I mean give your home diretory of your web to a network path and place your mdb in this web folder. Give read write access to this folder to IUSER.

let me know if it is possible..

neeraj523
I changed line of code to this line now according to Fritztb
objCon.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=\\Nigasfs\Coshare\Meter.mdb"
I got message
Error Type:
Microsoft JET Database Engine (0x80004005)
The Microsoft Jet database engine cannot open the file '\\Nigasfs\Coshare\Meter.mdb'. It is already opened exclusively by another user, or you need permission to view its data.
/MeterTracking/MeterTracking.asp, line 332

Do you guys think, now it is connecting to this Neteowrk drive and permissions with this changes error message
Please let me know

Thanks
Mike
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The reason why you are getting this new error is that necessary permissions for Reading / Writing have not been assigned to the mapped drive.

Here is the article that will show you how to fix that:


http://support.microsoft.com/default.aspx?scid=kb;en-us;Q184566

Fritz the Blank
Fritz the Blank

Finally I decided to change the script to connect to SQL server database and then Asdking DBA to write  DTS script to load the data into access database
 SOrry for the confusion I provided. I think For the time constraint I decided to go for this option becauae
Access also has problem opening by another user, if one user has it open, So onlu 1 person can open the databse at a time. that is the reason, i changed all my code to insert data in SQL server and Created aDTS script.

Well, if you go to SQL Server, many of your problems will dissappear for certain!

I am glad that you found a solution (though at least we finally got the path correct and were closing in on getting this done).

Please be sure to close out this question by accepting the comment that helped you the most as an answer.
Fritz BT
I have question,
When I try to debug the code with VB code, I am getting error while inserting the second record THe error
The Object variable or with  Block Varaible not set
Can you help me resolve this issue

Thanks
Mike
Mike--

It might be best to post that as a new question since it is a completely different issue (also more people will help as it is a new question).

If you don't have enough points to do that, then post the code in question here and we'll see what's what.

FtB
I did post as a different question, can you please take a look at the code.\Thanks for your response
Thanks
Mike
Question: Error running........
The Question titile is
Question Title: VB:Error While running application (The Object variable or with  Block Varaible not set)

Please take a look at this.
I am getting error, when I try to insert second record into database
with the error objectvariable...
for the variable sEmployyeID in 1st VB page

Please...
ASP Code
<%@ Language=VBScript %>
<!--#include file="resources\incConstants.asp"-->
<%
'**************************************************************************
'*  
'*  ASP Name: MeterTracking.asp
'*  Description: MeterTracking form is used for Fied Employees to enter the Meter Info
'*  Date Created:04/20/04
'*  Author: Vijitha Reddy
'*
'***********************************************************************
'Function / Sub Variables
Dim objCon            'Used for database connection
Dim sTempStr      'Temporary variable to hold the date values
Dim sTmpStr            'Temporary variable to hold the date values
Dim iTempVal      'Temporary variable to hold the date values
Dim iTmpVal            'Temporary variable to hold the date values

'Page Variables
Dim sForm(2)      'Variable to hold the form values
Dim sData(9,1)      'Variable to hold the Meter data values
Dim sErrMsg            'Variable to hold the error messages
Dim sQuery            'Variable to hold the query value
Dim iLp                  'Variable for looping the Meter Info
Dim iLoop            'Variable for looping the Meter Info
Dim bIsMeter      'Variable to check the flag for MeterInfo
Dim sRegions      'Variable to get the region info
Dim rsRegions      'Variable to loop the regions
Dim sEmployeeID                  'Variable used to hold the employeeId of the Employee
Dim sMeterDate                  'Variable used to hold the MeterDate for the Meter
Dim sRegion                        'Variable used to hold the region for the Meter
Dim sMeterSerialNo            'Variable used to hold the Meter SerialNo for the Meter
Dim nAutoID                        'Variable used to hold the AutoID
Dim sStatus                        'Variable used to hold the status IN/OUT for the Meter
Dim sReg(1)                        'Variable to hold the region value

'****************************************************
' Create/Format Input Dictionary to PageController  *
'****************************************************
Set oInputDict = Server.CreateObject("Scripting.Dictionary")
Set oInputDict = InitializeInput(cgFORMAT_AS_DICTIONARY, cgFORMAT_AS_DICTIONARY)
       
'**********************************************************      
' Create/Format Output Dictionary from PageController     *
'**********************************************************
Set oOutPutDict = Server.CreateObject("Scripting.Dictionary")
 
'Load IN/OUT Deafult
For iLp = 0 to 9
      sData(iLp,1) = "OUT"
Next

sReg(0) = "Bellwood"
sReg(1) = "Glen Ellyn"


'Get Passed Back Form Data After INSERT
If CBool(Request.QueryString("pass")) = True then
      sForm(0) = Request.QueryString("empid")
      sForm(1) = Request.QueryString("date")
      sForm(2) = Request.QueryString("reg")
End If

'Form Has Been Submitted
If Request.Form("Action") = "Add" then
      sErrMsg = ""

            'Collect Up The General Info
            For iLp = 0 to 2
                  sForm(iLp) = Trim(Request.Form("f_"&iLp))
            Next

            'Collect Up The Meter Info
            For iLp = 0 to 9
                  For iLoop = 0 to 1
                        sData(iLp,iLoop) = Trim(Request.Form("m_"&iLoop&"_"&iLp))
                  Next
            Next

      'Validation of form with proper values
      If sErrMsg = "" then
            'validation for Employee ID
            If (sForm(0) = "") or (sForm(0) = "99999") or not (IsNumeric(sForm(0)))or (Len(sForm(0)) <> 5) then
                        If sForm(0) = "" then
                              sErrMsg = "Error: Employee ID - Required field."
                        Elseif sForm(0) = "99999" or not IsNumeric(sForm(0))or (Len(sForm(0)) <> 5) then
                        sErrMsg = "Error: Employee ID - Invalid Value."
                        End If
                  Else
            
                        'validation for Date
                        If sForm(1) = "" then
                              sErrMsg = "Error: Date - Required Field."
                        Else
                              sForm(1) = PadDate(sForm(1))
                              If ValidateDate(sForm(1),sErrMsg) = True then
                                    sForm(1) = sErrMsg
                                    sErrMsg = ""
            
                                    'validation for Region
                                    If sForm(2) = "" then
                                          sErrMsg = "Error: Region - Required Field."
                                    Else
                                    sForm(2) = SetCap(sForm(2))

                                    'validation for Meter Info
                                    bIsMeter = False
                                    'If meter details yes, check for valid Meter info
                                    For iLp = 0 to 9
                                         If sData(iLp,0) <> "" then
                                              If Left(sData(iLp,0),1) = "7" then
                                                   sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Can't Start With 7."
                                              Else
                                                   If Len(sData(iLp,0)) <> 7 then
                                                        sErrMsg = "Error: Meter No (" & sData(iLp,0) & ") - Wrong Length."
                                                   Else
                                                        bIsMeter = True
                                                   End If
                                              End If
                                                                       
                                              If sErrMsg <> "" then
                                                   iLp = 9
                                              End If
                                         End If
                                    Next

                                          'Checking for Meter Details
                                          If sErrMsg = "" then
                                          'All Ok - INSERT Details into DB
                                                If bIsMeter = False then
                                                      sErrMsg = "Error: Meter No Details - Required."
                                                Else
                                                      If sErrMsg = "" then
                                                            For iLp = 0 to 9
                                                                  If sData(iLp,0) <> "" then
                                                                        sEmployeeID = SQL(sForm(0))
                                                                        sMeterDate = sForm(1)
                                                                        sRegion = SQL(sForm(2))
                                                                        sMeterSerialNo = SQL(sData(iLp,0))
                                                                        sStatus = sData(iLp,1)
                                                                        'Add the values to input dictionary
                                                                        oInputDict.Add "sEmployeeID", sEmployeeID
                                                                        oInputDict.Add "sMeterDate", sMeterDate
                                                                        oInputDict.Add "sRegion", sRegion
                                                                        oInputDict.Add "sMeterSerialNo", sMeterSerialNo
                                                                        oInputDict.Add "sStatus", sStatus
                                                                        '**********************************************************
                                                                        'Call the Page controller.
                                                                        '**********************************************************
                                                                        Set oPC = Server.CreateObject ("CmpMTCTRL.CMTCTRL")
                                                                        lPCResponseCode = oPC.ProcessPage(oInputDict, oOutputDict, sRedirectURL)
                                                                  End If
                                                            Next
                                                            Response.Redirect "MeterTracking.asp?pass=True&empid=" & sForm(0) & "&date=" & sForm(1) & "&reg=" & sForm(2)
                                                      End If
                                                End If
                                          End If
                                    End If
                              End If
                        End If
            End If
      End If
End If

CloseDB
%>
<html>
      <head>
            <title>Meter Information</title>
      </head>
<body>
      <table width="500" cellspacing="1" cellpadding="0" border="0" bgcolor="#000000" align=center>
            <form name="Reading" method="post" action="MeterTracking.asp">
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30"><b>M E T E R&nbsp;&nbsp;&nbsp;I N F O R M A T I O N</b></td>
                                    </tr>
                              </table>
                  <td>
                  </tr>
                  <%If sErrMsg <> "" then%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30"><font color="#FF0000"><%=sErrMsg%></font>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <%End If%>
                  <%If CBool(Request.QueryString("pass")) = True then%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30">Notice: Info Successfully inserted into DB.
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <%End If%>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td colspan="2" height="30"><b>General Details:</b></td>
                                    </tr>
                                    <tr>
                                          <td width="100" height="25">*Employee ID:
                                          </td>
                                          <td width="400">
                                                <input type="text" name="f_0" size="5" maxlength="5" value="<%=sForm(0)%>">
                                          </td>
                                    </tr>
                                    <tr>
                                          <td height="25">*Date:
                                          </td>
                                          <td>
                                                <input type="text" name="f_1" size="10" maxlength="10" value="<%=sForm(1)%>">(Ex-01/01/2004)
                                          </td>
                                    </tr>
                                    <tr>
                                          <td height="25">*Region:
                                          </td>
                                          <td>
                                                <select name="f_2">
                                                      <%If sForm(2) = "" then%>
                                                            <option value="">Please select</option>
                                                      <%End If
                                                      For iLp = 0 to UBound(sReg)
                                                            If sForm(2) = sReg(iLp) then%>
                                                                  <option value="<%=sReg(iLp)%>" selected><%=sReg(iLp)%></option>
                                                            <%Else%>
                                                                  <option value="<%=sReg(iLp)%>"><%=sReg(iLp)%></option>
                                                            <%End If
                                                    Next%>
                                                </select>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td colspan="4" height="30"><b>Meter Numbers:</b>
                                          </td>
                                    </tr>
                                    <%For iLp = 0 to 9%>
                                    <tr>
                                          <td width="100" height="25">Meter No:
                                          </td>
                                          <td width="125">
                                                <input type="text" name="m_0_<%=iLp%>" size="6" maxlength="7" value="<%=sData(iLp,0)%>"">(7 Digits)
                                          </td>
                                          <td width="50">Status:
                                          </td>
                                          <td width="225">
                                                <input type="radio" name="m_1_<%=iLp%>" value="OUT" <%If sData(iLp,1) = "OUT" then%>checked<%End If%>>&nbsp;OUT&nbsp;&nbsp;
                                                <input type="radio" name="m_1_<%=iLp%>" value="IN" <%If sData(iLp,1) = "IN" then%>checked<%End If%>>&nbsp;IN
                                          </td>
                                    </tr>
                                    <%Next%>
                              </table>
                        </td>
                  </tr>
                  <tr bgcolor="#FFFFFF">
                        <td>
                              <table width="500" cellspacing="0" cellpadding="2" border="0">
                                    <tr>
                                          <td height="30" align="center">
                                                <input type="hidden" name="Action" value="Add">
                                                <input type="submit" name="Button" value="Submit">
                                                <input id=reset name=reset type=reset value=Reset></TD>
                                          </td>
                                    </tr>
                              </table>
                        </td>
                  </tr>
            </form>
      </table>
</body>
</html>
<%
'Function for Date value
Function PadDate(Value)
If Len(Value) = 0 then
      PadDate = Value
Else
      If IsDate(Value) then
            sTmpStr = ""
            sTempStr = ""
            iTempVal = 0
            For iLp = 1 to Len(Value)
                  If IsNumeric(Mid(Value,iLp,1)) then
                        sTempStr = sTempStr & Mid(Value,iLp,1)
                  Else
                  If Len(sTempStr) > 2 then
                        PadDate = Value
                  Else
                        sTempStr = Left("00",2-Len(sTempStr)) & sTempStr & "/"
                        sTmpStr = sTmpStr & sTempStr
                        sTempStr = ""
                  End If
                  End If
            Next
                  If Len(sTempStr) > 4 then
                        PadDate = Value
                  Else
                        PadDate = sTmpStr & Left("2000",4-Len(sTempStr)) & sTempStr
                  End If
      Else
            PadDate = Value
      End If
End If
End Function

'Function for validating Date value entered by user
Function ValidateDate(Value, sErrMsg)
If Len(Value) <> 10 then
      ValidateDate = False
      sErrMsg = "Error: Date - Invalid."
Else
      If IsNumeric(Mid(Value,1,2)) and IsNumeric(Mid(Value,4,2)) and IsNumeric(Mid(Value,7,4)) then
            Value = Mid(Value,1,2) & "/" & Mid(Value,4,2) & "/" & Mid(Value,7,4)
            If IsDate(Value) then
                  ValidateDate = True
                  sErrMsg = Value
            Else
                  ValidateDate = False
                  sErrMsg = "Error: Date - Invalid."
            End If
      Else
            ValidateDate = False
            sErrMsg = "Error: Date - Invalid."
      End If
End If
End Function

'Function to replace quotes
Function SQL(Value)
SQL = Replace(Value,"'","''")
End Function

'Function used for capitilizing the values
Function SetCap(Value)
If Value <> "" Then
      sTempStr = ""
      sTempStr = sTempStr & UCase(Mid(Value, 1, 1))
      For iTempval = 2 To Len(Value)
            If Mid(Value, iTempval-1, 1) = " " Then
                  sTempStr = sTempStr & UCase(Mid(Value, iTempval, 1))
            Else
            sTempStr = sTempStr + Mid(Value, iTempval, 1)
            End If
      Next
      SetCap = sTempStr
End If
End Function

%>


'------------------------------------------------------------------------------------------------
VB CODe
Private Function ExecutePage(oInputDict As Scripting.Dictionary, oOutputDict As Scripting.Dictionary, sRedirectURL As String) As Long
Const cMETHOD_NAME As String = "ExecutePage"
   
' Start custom implementation code for declarations
    Dim sEmployeeID As String       'Variable used to hold the employeeId of the Employee
    Dim sMeterDate As String        'Variable used to hold the MeterDate for the Meter
    Dim sRegion As String    'Variable used to hold the region for the Meter
    Dim sMeterSerialNo As String    'Variable used to hold the Meter SerialNo for the Meter
    Dim nAutoID As Integer        'Variable used to hold the AutoID
    Dim sStatus As String   'Variable used to hold the status IN/OUT for the Meter
    Dim avRegions          'Array of regions to get records from database
    Dim objGetRegionsBO As CmpServerInterfaceMT.IMT    'Create objGetRegionsBO instance
    Dim objInsertMTBO As CmpServerInterfaceMT.IMT  'Create objInsertMTBO instance
   
   
    'Instantiate the CMTBO object
    Set objInsertMTBO = CreateObject("CmpMTBO.CMTBO")
    'Set objGetRegionsBO = CreateObject("CmpMTBO.CMTBO")
' End custom implementation code for declarations

' Start custom code
    'Add avRegions to Output Dictionary
    'oOutputDict.Add "avRegions", objGetRegionsBO.GetRegions()
 
    ' Add values to the Input Dictionary

    'If the data entered by the user is valid then get the values from the input dictionary
   
        ' Add values to the input dictionary
        sEmployeeID = Trim(CStr(oInputDict.Item("sEmployeeID")))
        sMeterDate = Trim(CStr(oInputDict.Item("sMeterDate")))
        sRegion = Trim(CStr(oInputDict.Item("sRegion")))
        'nAssocID = oInputDict.Item("nAssocID")
        sMeterSerialNo = oInputDict.Item("sMeterSerialNo")
        sStatus = oInputDict.Item("sStatus")
 
        'call the function to add the information to the database.
 
            Call objInsertMTBO.InsertMeterInfo(sEmployeeID, sMeterDate, sRegion, sMeterSerialNo, sStatus)
                           
 ' End custom code
   
On Error GoTo ErrorHandler
   
ErrorHandler:

' Start cleanup of custom implementation's objects
    'Clean up memory by destroying the Instantiated object
    objInsertMTBO = Nothing
' End cleanup of custom implementation's objects
If Err.Number <> 0 Then
        HandleError ArchitectureError, cmCLASS_NAME, cMETHOD_NAME
    End If
End Function
'--------------------------------------------------------------------------------------------------
2nd LayerVB CODe
Private Function InsertMeterInfo(ByVal sEmployeeID As String, _
                         ByVal sMeterDate As String, _
                         ByVal sRegion As String, _
                         ByVal sMeterSerialNo As String, _
                         ByVal sStatus As String) As Variant


    Const cSPInsert_MeterInfo As String = "ProcGasMeterInfo"    'Dim Variable to Store Stored procedure Name
    Const c_sParameterName As String = "InsertMeterInfo"              'Dim Variable to Store the Method Name
   
    Dim objDatabaseSvc As ACAIC.IDatabaseSvc        'Dim Variable to implement ACA database services
    Dim sConnectionString As String                 'Dim Variable to Store Connection String
    Dim avInputParam As Variant                     'Dim Variable to Store input Parameters for Stored Procedure
   
    On Error GoTo ErrorHandler

    'Instantiates the Data Base Factory Object
    Set objDatabaseSvc = DBSvcFactory(cmClassName)
   
    'Get connection string for the CMTBO from ACAConfig.xml
    sConnectionString = GetConnectionString(cmClassName)
   
    'Get the input parameter list and create parameter array
    avInputParam = Array(MakeParameter("sEmployeeID", adodb.adChar, sEmployeeID), _
                    MakeParameter("sMeterDate", adodb.adChar, sMeterDate), _
                    MakeParameter("sRegion", adodb.adChar, sRegion), _
                    MakeParameter("sMeterSerialNo", adodb.adChar, sMeterSerialNo), _
                    MakeParameter("sStatus", adodb.adChar, sStatus))

     'Calls the Stored Procedure 'ProcGasMeterInfo'
      Call objDatabaseSvc.RunSP(cSPInsert_MeterInfo, avInputParam, sConnectionString)
     
ErrorHandler:
    'Removes the objects from memory
    Set objDatabaseSvc = Nothing
    'Handle possible errors
    If Err.Number <> 0 Then
        HandleError ApplicationError, cmClassName, c_sParameterName
    End If
End Function
'------------------------------------------------------------------------------
3rd layer VB code
Public Function InsertMeterInfo(ByVal sEmployeeID As String, _
                         ByVal sMeterDate As String, _
                         ByVal sRegion As String, _
                         ByVal sMeterSerialNo As String, _
                         ByVal sStatus As String) As Variant
End Function
'-----------------------------------------
Stored Procedure
CREATE Procedure procGasMeterInsert

(@sEmployeeID           varchar(20),
@sMeterDate             varchar(30),
@sRegion             varchar(128),
@sMeterSerialNo             varchar(128),
@sStatus                     varchar(20)
    )

As


INSERT INTO GasMeterTrack (EmployeeID, MeterDate, Region, MeterSerialNo, Status) VALUES(
            @sEmployeeID,
                     @sMeterDate,
                      @sRegion,
                     @sMeterSerialNo,
                      @sStatus
                    )
GO