Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WNetCancelConnection2 ERROR_NOT_CONNECTED

Status
Not open for further replies.

Xerus

Programmer
Jan 30, 2007
6
US
I figured out my problem creating a network connection but now can't seem to disconnect anything I create even though I can go to my computer and see that the drive is physically there and navigate through it.

I keep getting error 2250 ERROR_NOT_CONNECTED.

Here's my disconnect code

Code:
Public Function DestroyNetworkConnection() As Long
        Dim ErrInfo As Long
        Dim strError As New StringBuilder

        
        ErrInfo = WNetCancelConnection2(TEMP_DRIVE, CONNECT_UPDATE_PROFILE, 0)

        DestroyNetworkConnection = ErrInfo
      
    End Function

WNetCancelConnection is as follows:

Code:
 Public Declare Ansi Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" ( _
        ByRef lpName As String, _
        ByVal dwFlags As Integer, _
        ByVal fForce As Boolean) _
        As Integer

If I try to pass the lpName ByVal I get a P/Invoke stack error.

Any thoughts are much appreciated.



----------
Sam

"Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest."

- Isaac Asimov
 
Xerus,

Try declaring your function like this
Code:
Private Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
Instead of Public Declare Ansi Function, then change your destroyconnection to
Code:
Public Function DestroyNetworkConnection() As [b]Integer[/b]
   Dim ErrInfo As [b]Integer[/b]
   Dim strError As New StringBuilder
   ErrInfo = WNetCancelConnection2(TEMP_DRIVE, CONNECT_UPDATE_PROFILE, 0)
   If ErrInfo= 2250 Then
   'No problem, this error is network connection does not exist.
                Return ErrInfo
            End If
   Return ErrInfo
End Function
And see if this solves your problem.

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT * FROM Users WHERE clue > 0
0 Rows Returned

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Thank worked..Thanks.

Sam

----------
Sam

"Part of the inhumanity of the computer is that, once it is competently programmed and working smoothly, it is completely honest."

- Isaac Asimov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top