Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > .NET Web Services
|
.NET Web Services Discussions about .NET XML Web Service technologies including ASMX files, WSDL and SOAP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Web Services section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2003, 08:32 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Public Class DB2

    Private Shared m_objConn As SqlConnection

    Public Shared Function SqlCon() As SqlConnection
        m_objConn = New SqlConnection
        m_objConn.ConnectionString = "packet size=4096;user id=User;PWD=Password;data source=192.168.0.10;persist security info=False;Database=BASE"
        m_objConn.Open()
        Return m_objConn
    End Function 'CreateSqlConnection

    Public Shared Sub SqlDisCon()
        If Not m_objConn Is Nothing Then
            If m_objConn.State = ConnectionState.Open Then
                m_objConn.Close()
                m_objConn = Nothing
            End If
        End If
    End Sub

End Class


Peter
 
Old December 16th, 2003, 09:03 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just a little update from last time:
My page globalvar.vb now contains a number of functions I call when needed in my pages. I'll post them here (Thay may be of use to somebody somewhere (I hope.. he hehe))
My page (Globalvar.vb) starts like this:
'*********************PAGE START*********************
Imports System.Data.SqlClient

Friend Class SQL
    Private Shared m_objConn As SqlConnection
    Private Shared m_objConn2 As SqlConnection
    ' CONSTANTS
    Public Const DbString As String = "packet size=4096;user id=username;PWD=password;data source=sql.mydomain.com;persist security info=False;Database=MYBASE"
    Public Const DbString2 As String = "packet size=4096;user id=username;PWD=password;data source=sql.mydomain.com;persist security info=False;Database=MYBASE"
    Public Const AuthCODE As String = "hRE74mF4Loogh38s64jF9Llots5noF6Sj83NsD59sM" 'DO NOT MODIFY
    Public Const UploadCatalog As String = "D:\inetpub\wwwroot\myweb\upload\"
 
Old December 16th, 2003, 09:13 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This next bit I use to call up an SQL connection on any page on my site.
'**************GETTING AN SQL CONNECTION*****************
    Public Shared Function Connect() As SqlConnection
        m_objConn = New SqlConnection
        m_objConn.ConnectionString = DbString '**Using the constant above
        m_objConn.Open()
        Return m_objConn
    End Function '**CreateSqlConnection
    Public Shared Function Connect2() As SqlConnection
        m_objConn2 = New SqlConnection
        m_objConn2.ConnectionString = DbString'**Using the constant above
        m_objConn2.Open()
        Return m_objConn2
    End Function '**CreateSqlConnection
'***************END SQL CONNECTION IN globalvar.vb*************


'*****************TO USE THE CODE ABOVE IN MYPAGE.ASPX*********************
Dim SQ As Data.SqlClient.SqlDataReader
        Dim SQLConnect As Data.SqlClient.SqlConnection
        SQLConnect = SQL.Connect()
        Dim SQLCmd As New System.Data.SqlClient.SqlCommand("set dateformat dmy", SQLConnect)

        '************************************************* *******************
        'Get info from table TABLE
        '************************************************* *******************
        Dim strVar1, strVar2 As String
        Try
            SQLCmd.CommandText = ("select SQLVar1, SQLVar2 from TABLE where Var1 = '" & Session.Item("AnyVar") & "'")
            SQ = SQLCmd.ExecuteReader()
            Do While SQ.Read = True
                strVar1 = SQ("SQLVar1")
                strVar2 = SQ("SQLVar2")
                strmeNick = SQ("meNick")
            Loop
        Catch ex As Exception
            Response.Write("Error in mypage.aspx: " & ex.Message)
        Finally
            SQ.Close()
            SQLCmd.Connection.Close()
            SQLConnect.Close()
        End Try
'********************END USING CODE*******************************

------------------------
All help is Good help!
Regards
Michael
 
Old December 16th, 2003, 09:18 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This next part is to just execte an SQL command like INSERT, DELETE, UPDATE....
'****************CODE TO EXECUTE SQL COMMANDS IN Globalvar.vb*************
    Public Shared Function Execute(ByVal SQLStatement As String) As Boolean
        Dim SQLConnection As New System.Data.SqlClient.SqlConnection
        Dim SQLCommand1 As New System.Data.SqlClient.SqlCommand
        Try
            SQLConnection.ConnectionString = DbString
            SQLConnection.Open()
        Catch ex As Exception
            Try
                SQLConnection.ConnectionString = DbString2
                SQLConnection.Open()
            Catch ex1 As Exception
            End Try
        End Try
        SQLCommand1.Connection = SQLConnection
        SQLCommand1.CommandText = SQLStatement
        SQLCommand1.ExecuteNonQuery()
        SQLConnection.Close()
    End Function
'************END EXECUTE SQL COMMAND IN Globalvar.vb*************

'*************TO USE THE CODE ABOVE IN MYPAGE.ASPX**************
SQL.Execute("Insert into TABLE (SQLVar1, SQLVar2)" values ('" & Request("strVar1") & "', '" & SQL.URLEncode(Textbox1.Text) & "')")
'*************END USE THE CODE ABOVE IN MYPAGE.ASPX**************

------------------------
All help is Good help!
Regards
Michael
 
Old December 16th, 2003, 09:24 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This here is a nice way to URL encode a string for use with sending SMS ++
'********URL ENCODE A STRING in Globalvar.vb******************
Public Shared Function URLEncode(ByVal strData As String) As String

        Dim i As Integer
        Dim strTemp As String
        Dim strChar As String
        Dim strOut As String
        Dim intAsc As Integer

        strTemp = Trim(strData)
        For i = 1 To Len(strTemp)
            strChar = Mid(strTemp, i, 1)
            intAsc = Asc(strChar)
            Select Case intAsc
                Case 48 To 57, 65 To 90, 97 To 122
                    strOut = strOut & strChar
                Case Else
                    strOut = strOut & "%" & Hex(intAsc)
            End Select
        Next i
        strOut = Replace(strOut, "%D%A", "%0d%0a")
        strOut = Replace(strOut, "linBR", "%0d%0a")
        URLEncode = strOut
End Function
'******************END globalvar.vb CODE***************

'*************TO USE THE CODE ABOVE IN MYPAGE.ASPX**************
Dim strEncodedText as String = SQL.URLEncode(TextBox1.Text)
Response.Write("Encoded text from textbox: " & strEncodedText)
'*************END USE THE CODE ABOVE IN MYPAGE.ASPX**************

------------------------
All help is Good help!
Regards
Michael
 
Old December 16th, 2003, 09:27 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This here is to decode the string
'*******TO DECODE THE STRING in Globalvar.vb*************
Public Shared Function URLDecode(ByVal strConvert)
        Dim arySplit
        Dim strHex
        Dim strOutput
        Dim i As Integer
        Dim letter

        If strConvert = "" Then
            URLDecode = ""
            Exit Function
        End If

        '**First convert the + to a space
        strOutput = Replace(strConvert, "+", " ")
        '**Convert %0d%0a to linebreake for ASPX
        strOutput = Replace(strConvert, "%0d%0a", "%3Cbr%3E")

        '**Then convert the %number to normal code
        arySplit = Split(strOutput, "%")

        If IsArray(arySplit) Then
            strOutput = arySplit(i)
            For i = LBound(arySplit) To UBound(arySplit) - 1
                strHex = "&H" & Mid(arySplit(i + 1), 1, 2)
                letter = Chr(strHex)
                strOutput = strOutput & letter & Right(arySplit(i + 1), Len(arySplit(i + 1)) - 2)
            Next
        End If
        URLDecode = strOutput
End Function
'******************END globalvar.vb CODE***************

'*************TO USE THE CODE ABOVE IN MYPAGE.ASPX**************
Dim strDecodedText as String = SQL.URLDecode(strEncodedText)
Response.Write("Decoded text: " & strDecodedText)
'*************END USE THE CODE ABOVE IN MYPAGE.ASPX**************
 
Old December 16th, 2003, 09:34 PM
Authorized User
 
Join Date: Oct 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This last bit is a unique ID creator and a random 4 digit password generator

'*******UNIQUE ID AND PWD GENERATOR in Globalvar.vb*************
    Public Shared Function SMSID()
        SMSID = Right(Now.Year, 2) & Format(Now.Month, "00") & Format(Now.Day, "00") & Format(Now.Hour, "00") & Format(Now.Minute, "00") & Format(Now.Second, "00") & Format(Now.Millisecond, "0000")
    End Function

    Public Shared Function rndPassword()
        Dim pwd, i, ch
        pwd = Second(Now())
        pwd = pwd & Int(437657 * Rnd())
        For i = 1 To 6
            Randomize()
            ch = Int(26 * Rnd()) + 97 & Second(Now())
            pwd = pwd & ch
            If i = 3 Then pwd = pwd & Second(Now())
        Next
        pwd = Right(pwd, 4)
        rndPassword = pwd
    End Function
End Class

'******************END globalvar.vb CODE***************

'*************TO USE THE CODE ABOVE IN MYPAGE.ASPX**************
'**Unique ID
Response.Write("Unique ID: " & SQL.SMSID)
'Random Password
Response.Write("Random Password: " & SQL.rndPassword())

'*************END USE THE CODE ABOVE IN MYPAGE.ASPX**************

After all the help I have received here in Wrox, I hope this will be useful to someone out there.


------------------------
All help is Good help!
Regards
Michael





Similar Threads
Thread Thread Starter Forum Replies Last Post
Global ADO Connection to SQL ? debbiecoates VB Databases Basics 2 October 29th, 2007 03:22 AM
How to create a Global Database connection? chrislepingwell ADO.NET 6 November 8th, 2006 07:20 PM
Global Connection Object sarahmapg ADO.NET 1 May 18th, 2005 06:00 AM
Global SQL Connection tallbry VB Databases Basics 2 November 8th, 2004 10:58 PM
Global ADO Connection object DaveParry123 ADO.NET 0 October 7th, 2003 03:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.