Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Dim networkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
        Dim firstNetwork = networkInterface.FirstOrDefault(Function(x As System.Net.NetworkInformation.NetworkInterface) _
            x.OperationalStatus = System.Net.NetworkInformation.OperationalStatus.Up)
        Dim firstMacAddressOfWorkingNetworkAdapter = firstNetwork.GetPhysicalAddress()
        Dim connString As String = "Server=tserver;Database=database;Uid=usr;Pwd=ps;"
        Dim sqlQuery As String = "SELECT * FROM Computers WHERE MacAddress='" & firstMacAddressOfWorkingNetworkAdapter.ToString & "'"
        Dim command As MySqlCommand
        Dim mysqlconn = New MySqlConnection
        Dim reader As MySqlDataReader
        mysqlconn.ConnectionString = connString
        mysqlconn.Open()
        Try
            command = New MySqlCommand(sqlQuery, mysqlconn)
            reader = command.ExecuteReader
            While reader.Read
                If firstMacAddressOfWorkingNetworkAdapter.ToString = reader.GetString("MacAddress") Then
                    Consoletxt("Computer Found '" + reader.GetString("ComputerName") + "'")
                    Consoletxt("MAC Address OK  --  " + firstMacAddressOfWorkingNetworkAdapter.ToString)
                    Login.Domain.Text = reader.GetString("Domain")
                Else
                    Consoletxt("Could not find your computer in our database")
                    Consoletxt("Starting Setup")
                    Thread.Sleep(5000)
                    SetupBackground.Mode.Text = "domain"
                    MyBase.Update()
                    SetupBackground.Show()
                    Me.WindowState = FormWindowState.Minimized
                    Me.ShowInTaskbar = False
                    Check.Text = "setup"
                End If
            End While
        Catch ex As Exception
            
        End Try
        mysqlconn.Close()


I've tried to get this code to work but it just skips the while reader.read for some reason. All of my other pieces where set out similar but they all work.

Can anyone help :/ ?
Posted
Updated 13-Sep-14 9:57am
v2
Comments
[no name] 13-Sep-14 16:34pm    
Debug it and find out. It's most likely skipping the while because your reader has nothing to read.

Your way of handling the exceptions in fact hides their occurrence. If the DataReader throws, you'll never know. Please handle sensibly the exceptions, in order to debug effectively your program.
 
Share this answer
 
Comments
Nelek 13-Sep-14 19:52pm    
What for? Someone will tell him the error so he can to the next piece of code... Self investigate is time expensive, didn't you know that?
Sergey Alexandrovich Kryukov 13-Sep-14 19:58pm    
:-)
Sergey Alexandrovich Kryukov 13-Sep-14 19:57pm    
5ed.
Remember, I was mentioning that there are cases when blocking propagation of exception is really needed. This is not one of such cases. Just the opposite: this is the case when blocking it is really a crime of a developer. It would be much better not to handle exceptions in this context at all.

—SA
CPallini 14-Sep-14 13:10pm    
Indeed.
Thank you.
Thanks Guys.
i didn't forgot that when there is not record of what it is finding it does not tell you. I found that my mac address in my database a wrong character thus it would just skip the reader.read(). I kinda feel stupid now but oh well. I kept adding breakpoints trying to find the error but couldn't until i looked at my database.

Thanks guys once again,
Alex
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900