Question

My Program is "Searching Employee" Use VB web application in Visual Studio 2008 and I use Database in Microsoft Access

I program it in my computer it work 100%. But When I move the project to other computer for upload to server, it have error

ODBC--connection to 'SQL ServerWDT02418\SQLEXPRESS' failed.

WDT02418 is my Computer's name. But I run the project in other computer.

I use the Database connection like this

Function CountEmpData(ByVal EN As String, ByVal Area As String, ByVal Product_type As String) As Integer
    Dim CounterEmpData As Integer

    Try

        Dim ole As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PROJECT_WD\e-OJT_Project6\Database\Employee.mdb")
        ole.Open()
        Dim sqlCommand As String = "SELECT COUNT(*) AS 'Counter' FROM Employee WHERE (Emp_ID LIKE '%" + EN + "%') AND (Area LIKE '%" + Area + "%') AND (Product_Type LIKE '%" + Product_type + "%')"
        Dim myCommand As New OleDbCommand(sqlCommand, ole)
        Dim myReader As OleDbDataReader = myCommand.ExecuteReader()
        While myReader.Read()
            CounterEmpData = myReader.GetInt32(0)
        End While
        myReader.Close()
        ole.Close()

    Catch ex As Exception

    End Try

    Return CounterEmpData
End Function

It alert error at line

Dim myReader As OleDbDataReader = myCommand.ExecuteReader()

Someone please help me!!

Was it helpful?

Solution

There's nothing computer-specific in the code above, apart from the location of the Access file, but the absence of that wouldn't produce the error above. So I think the problem must lie in your .mdb database, and I suspect the issue is that it contains tables that are linked to a SQL Server which only code running on your machine can get to.

I would troubleshoot this by using the Microsoft Access UI to open the access database on one of the other computers, opening the Employee table and seeing if you still get an error. If you do, you'll know that it's the Access database that's at fault rather than your code. I would guess at this point that remote connections are not set up on SQL Server Express (see here to find out how to enable remote connections), or some firewall rule on your machine is preventing other machines from connecting to the instance of SQL Server Express, so I'd open Windows Firewall and allow inbound traffic on the port that SQL Server Express is listening on, or (better) move the SQL Server from your local machine to a dedicated development server.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top