1

I have been unable to get a legacy VB.NET ASP site to run.

So, I tried creating a new one from scratch, adding folders and files one-by-one to it, from the legacy project. However, it does not recognize the SQLServer class and is now at the point where it generates 106 errors when building.

Thus, I have started over yet again. I created a new project > Templates > Visual Basic > Web > ASP.NET Web Aplication. and added the class that references SQL stuff first, to try to get at the root of the problem.

To do this, imitating the legacy project, I added an App_Code folder to the project, and then added commonClass.vb to it, and started copying over functions, one at a time. First, I added the Imports clauses, and then a couple of functions:

Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Data
Imports DAL05.DataAccess
Imports System

Public Class commonClass

    Public Shared Function GetImages(ByVal MemberNo As String, ByVal ImageID As String, ByVal FileName As String) As DataView
        Dim ds As New DataSet()
        Dim SQLstring As String = "EXEC up_GettyImages '" & MemberNo & "','" & ImageID & "','" & FileName & "'"
        Dim Command As New SqlDataAdapter(SQLstring, System.Configuration.ConfigurationManager.AppSettings("OrderEnterConnection"))
        Command.Fill(ds, "xImages")
        Dim dv As DataView
        dv = ds.Tables("xImages").DefaultView()
        Return dv
    End Function

        Public Function GetPortalMenuItems() As DataSet
        Dim dset As New DataSet
        dset.ReadXml(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/PortalMenuItems.xml"))
        Return dset
    End Function

End Class

Here appears the first problem: the last "s" in Imports DAL05.DataAccess has a red underscore, but clicking "Error Correction Options" says, "no correction suggestions"

Apparently it doesn't know what DAL05.DataAccess is; so I looked for a "References" folder in my project - there isn't one. The legacy project has a Bin folder with DAL05:

enter image description here

I had a problem with/question about adding this, too, here.

So is it that the legacy project targets .NET Framework 3.5, and the new one targets 4.5 that is causing the mismatch/confusion? Is DAL05.DataAccess the wrong thing to import? Has it been superseded by something else?

Under Project > Properties > References > Imported namespaces, I added "Microsoft.SqlServer", which then let me know that some of my Imports were unnecessary, so that I now only have:

Imports System.Data.SqlClient
Imports System.Data

...but when I added this method:

Public Function LogAction(ByVal SessionID As String, ByVal userId As String, ByVal action As String, ByVal comment As String) As DataTable
    Dim sqlDAL As New SQLServer(System.Configuration.ConfigurationManager.AppSettings("OrderEnterConnection"))
    Dim SQLstring As String = "Exec fredFlintstone '" & SessionID & "','" & userId & "','" & action & "','" & comment & "'"
    Dim dset As DataSet
    dset = sqlDAL.runSQLDataSet(SQLstring)
    Return dset.Tables(0)
End Function

...SQLServer is redded up, and the "helpful hint" there tells me:

Type 'SQLServer' is not defined.

...with the following options:

Change 'SQLServer' to 'SQLError'
Generate 'Class SQLServer'
Generate new type...

None of these options seem sensible to me.

If it's really not possible to use the SQLServer class, what should I use instead?

UPDATE

Even stranger to me (maybe because I am a stranger to VB) is that, although "SQLServer" is red in the editor and unrecognized, when I rebuild the project, it succeeds? How could that be?

If I F5 the project, it does fail:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: BC30002: Type 'SQLServer' is not defined.

Source Error:    

Line 21: 
Line 22:     Public Function LogAction(ByVal SessionID As String, ByVal userId As String, ByVal action As String, ByVal comment As String) As DataTable
Line 23:         Dim sqlDAL As New SQLServer(System.Configuration.ConfigurationManager.AppSettings("OrderEnterConnection"))
Line 24:         Dim SQLstring As String = "Exec sp_LogAction_Net '" & SessionID & "','" & userId & "','" & action & "','" & comment & "'"
Line 25:         Dim dset As DataSet

Source File: C:\Projects\MemberOrderEntryNew\MemberOrderEntry3\MemberOrderEntry3\App_Code\commonClass.vb    Line: 23

...but that it (re)builds fine is confusing to me.

UPDATE 2

I also tried System.Data.SQLClient, but to no avail - it has the same problem as "SQLServer":

enter image description here

Community
  • 1
  • 1
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    `DAL05` appears to be some custom dll. Maybe there is a project on the computer where this app was originally developed with the source code for it. Otherwise, look up how to load a dataset from SQL Server. If you include the code for the `fredFlintstone` stored procedure to show its parameters, maybe we could help you with it for this instance - I'm sure you'll be able to use that for the other occurrences of similar code. – Andrew Morton Dec 05 '16 at 19:41
  • 1
    Ooh, now that I've coded what I thought would be a useful example for you, it seems to me that there is no need to return anything *if* the function and stored procedure names are meaningful. It would help to know what `sp_LogAction_Net` returns and how it is used (if at all) in calls to `LogAction`. – Andrew Morton Dec 05 '16 at 20:04
  • 1
    The VS Object Browser can show you what is in that DAL dll (which appears to be a debug build). In the References list, pick it and right click, select View in Object Browser. You should be able to at least see what is in it, namespaces, class names, methods. etc which might shed some light on things. – Ňɏssa Pøngjǣrdenlarp Dec 05 '16 at 20:31
  • ...for instance this post shows `Imports DAL05.DataAccess` which wont help if there is also a `DAL05.SQLServer` namespace or class which is needed – Ňɏssa Pøngjǣrdenlarp Dec 05 '16 at 20:38
  • @AndrewMorton: In the legacy code, a table is returned: Return dset.Tables(0) You cannot assume that function and SP names are sensible, unfortunately. – B. Clay Shannon-B. Crow Raven Dec 05 '16 at 21:06
  • @B.ClayShannon Although a datatable is returned from the function, is anything from it actually used? It could be that the original developer simply returned a datatable for any and all DB operations. – Andrew Morton Dec 05 '16 at 21:10
  • @AndrewMorton: I don't know; I haven't gotten that far with it (actually understanding what happens); I'm simply trying to get it to build, at this point. I see now that DAL05 *is* a custom DLL, as you surmised, and when the "Imports DAL05.DataAccess" is removed from the legacy app, it complains that "SQLServer" cannot be found. So that's what I need to add to the project, but am still trying to figure out how to do that - there is no "References" folder, so I don't know how to add this custom DLL to the project... – B. Clay Shannon-B. Crow Raven Dec 05 '16 at 21:12
  • What is listed in Project > Properties > References > References? Do you have System.Data.dll and DAL05.dll referenced? Also, in VS prior to 2015, to show the References node in Solution Explorer for VB projects you need to click the Show All Files button on the solution explorer toolbar. Sorry if if you've already checked these - it's getting hard to tell how far you have got! :-) – Mark Dec 05 '16 at 21:15
  • OK, right-click project, Add > Reference does it, but where is it added? Some config file or so? – B. Clay Shannon-B. Crow Raven Dec 05 '16 at 21:15
  • @Mark: Ah, thanks - "Show All Files" does the trick. Why would that be hidden by default? Bizarre, if you ask me... – B. Clay Shannon-B. Crow Raven Dec 05 '16 at 21:17
  • 1
    In VS2015 is it visible by default for VB projects - not sure why it was hidden in prior versions. The Project > Properties > References > References: box shows the same thing with more detail, and I usually use that (you can also add references from there). References are stored in the .vbproj file. – Mark Dec 05 '16 at 21:20

3 Answers3

2

Here are two options for replacing the LogAction method:

Public Function LogActionOption1(SessionID As String, userId As String, action As String, comment As String) As DataTable
    Dim dt As New DataTable

    Using sqlConn As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("OrderEnterConnection"))
        Using sqlCmd As New SqlCommand("sp_LogAction_Net", sqlConn)
            sqlCmd.CommandType = CommandType.StoredProcedure
            'TODO: REQUIRED - set the parameter names, types and sizes to comply with the declarations in the stored procedure.
            ' Note: sessionid is expected to be a 24-character string: http://stackoverflow.com/a/3518523/1115360
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@SessionId", .SqlDbType = SqlDbType.Char, .Size = 24, .Value = SessionID})
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@userId", .SqlDbType = SqlDbType.NVarChar, .Size = 50, .Value = userId})
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@action", .SqlDbType = SqlDbType.NVarChar, .Size = 16, .Value = action})
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@comment", .SqlDbType = SqlDbType.NVarChar, .Size = 500, .Value = comment})
            Dim da As New SqlDataAdapter(sqlCmd)
            da.Fill(dt)
        End Using
    End Using

    Return dt

End Function

However, it could be that the returned datatable is not actually used, or not used in a way that justifies using a datatable.

If it is only required to confirm that the data was added to the database:

Public Function LogActionOption2(SessionID As String, userId As String, action As String, comment As String) As Boolean
    Dim success As Boolean = False
    Dim dt As New DataTable

    Using sqlConn As New SqlConnection(System.Configuration.ConfigurationManager.AppSettings("OrderEnterConnection"))
        Using sqlCmd As New SqlCommand("sp_LogAction_Net", sqlConn)
            sqlCmd.CommandType = CommandType.StoredProcedure
            'TODO: REQUIRED - set the parameter names, types and sizes to comply with the declarations in the stored procedure.
            ' Note: sessionid is expected to be a 24-character string: http://stackoverflow.com/a/3518523/1115360
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@SessionId", .SqlDbType = SqlDbType.Char, .Size = 24, .Value = SessionID})
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@userId", .SqlDbType = SqlDbType.NVarChar, .Size = 50, .Value = userId})
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@action", .SqlDbType = SqlDbType.NVarChar, .Size = 16, .Value = action})
            sqlCmd.Parameters.Add(New SqlParameter With {.ParameterName = "@comment", .SqlDbType = SqlDbType.NVarChar, .Size = 500, .Value = comment})

            sqlConn.Open()
            success = (sqlCmd.ExecuteNonQuery > 0)
            sqlConn.Close()

        End Using
    End Using

    Return success

End Function

And if even that minimal feedback is not used, you can easily change that into a Sub.

P.S. If you end up modifying the stored procedures, you should avoid prefixing them with "sp_": Is the sp_ prefix still a no-no?

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
1

Based on the information you've provided thus far, it's not clear why you need the DAL05 dll at all. If you can connect to SQL Server with the standard System.Data.SqlClient objects, use those and ditch Dal05.

If you absolutely have to know what Dal05 is doing and how it works, grab Telerik's JustDecompile (it's free) and (assuming it's a .NET dll) you will be able to view the source to find out what it is doing and how its classes work.

DWRoelands
  • 4,878
  • 4
  • 29
  • 42
0

I got the MembesOrderEntry project to build and run, displaying the login page in the browser.

The next step is updating the Telerik DLLs. Which ones shall I use? The ones in ?

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862