Khin

hi all,
i having a problem to access server folder.
i got one folder inside server, which i already shared.
but when i access that folder fail.

dim host as string = "\\serverId\folder\file.xml"
doc.Load(host)
.....

error :System.IO.IOException = {"Logon failure: unknown user name or bad password.

how i pass the user name and password

any one help please.........


Re: Visual Basic General Access server file from client

Bruno Yu - MSFT

Khin,

Once I wrote a program that access remote server xls file as the data source shown in DataGrid on a form. The connection string for the data source is just like the host string in your code. I don't think there is anything wrong with your code string.

Generallly speaking, if you would like to access remote computer in Windows operating system, you'd better make shre the remote computer is allowed anoymous access, or your user name is added with enough pwoer. When you access the remote computer with $ after the folder name, the User Name and Password is needed. However, if you have the access to connect to the server, you can open the file directly in Windows Explorer.

Any questions on it Please reply me.






Re: Visual Basic General Access server file from client

Khin

hi bruno,

ya. i know that. but i got hudrend of clients, it is not posible for me to go to every client to add. the folder is share in server. is it have any where that i can do it with coding like passing the password and username to access because regrading to the error is server side request password and username for access

Thanks for reply





Re: Visual Basic General Access server file from client

Bruno Yu - MSFT

Khin,

This question referes to the architecture of your project. I guess your project is the Client/Server but not the Browser/Server.

1. Do you have the database on the server side that stores all the user's name and password I guess you don't. So just use the anoymours access for the client side.

2. How do you recoganize your client side I cannot imagin the situation. Maybe you could consider to change the client server side to browsers. :-)

3. You can also write the user name and password in your code stored in two strings and just login directly from the client side without input any user name or password. Just all by default shown in the client side in their Login textbox.






Re: Visual Basic General Access server file from client

Khin

Bruno,

Thanks again for reply me.

i would like to know more about the no3. i already searching for solution like no3. but cant. can you show me some example for passing username and password in coding

Thanks





Re: Visual Basic General Access server file from client

Bruno Yu - MSFT

Khin,

I don't exactly on your project situation specifically, however, there are two examples in code project that are similar to your current project. Please read the following examples:

'A request for a password

Private Sub FileSrv_OnNeedPassword1(ByVal sender As Object, ByVal e As _

AxbsFileServerSDK.IBSFileSrvXEvents_OnNeedPasswordEvent) _

Handles FileSrv.OnNeedPassword

If e.aUsername = "" Then

'this is the user Guest

e.aOkay = True

Else

'Unknown user, we accept only Guest

e.aOkay = False

End If

End Sub

'Values to use

Const localFile As String = "C:\myfile.bin"

Const remoteFile As String = "/pub/myftpfile.bin"

Const host As String = "ftp://ftp.myhost.com"

Const username As String = "myuserid"

Const password As String = "mypassword"

'1. Create a request: must be in ftp://hostname format,

' not just ftp.myhost.com

Dim URI As String = host & remoteFile

Dim ftp As System.Net.FtpWebRequest = _

CType(FtpWebRequest.Create(URI), FtpWebRequest)

'2. Set credentials

ftp.Credentials = New _

System.Net.NetworkCredential(username, password)

'3. Settings and action

ftp.KeepAlive = False

'we want a binary transfer, not textual data

ftp.UseBinary = True

'Define the action required (in this case, download a file)

ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

'4. If we were using a method that uploads data e.g. UploadFile

' we would open the ftp.GetRequestStream here an send the data

'5. Get the response to the Ftp request and the associated stream

Using response As System.Net.FtpWebResponse = _

CType(ftp.GetResponse, System.Net.FtpWebResponse)

Using responseStream As IO.Stream = response.GetResponseStream

'loop to read & write to file

Using fs As New IO.FileStream(localFile, IO.FileMode.Create)

Dim buffer(2047) As Byte

Dim read As Integer = 0

Do

read = responseStream.Read(buffer, 0, buffer.Length)

fs.Write(buffer, 0, read)

Loop Until read = 0 'see Note(1)

responseStream.Close()

fs.Flush()

fs.Close()

End Using

responseStream.Close()

End Using

response.Close()

End Using






Re: Visual Basic General Access server file from client

Khin

hi bruno,

the 1st solution is ok, but it needed external DLL to support it, so i wondering to use it because the license issue.

and the 2nd is the FTP method, if i use it, i need to set my server side as FTP server, this already run out of my project scope.

Thanks for for solutions.

any one have any idea to pass password and username to access server folder





Re: Visual Basic General Access server file from client

Bruno Yu - MSFT

Khin,

Please try the following code, hope that helps.

Dim query As String

Dim cmd As New OleDbCommand

query = "SELECT Password FROM Passwords WHERE " & _

"UserName= "

cmd = New OleDbCommand(query, conn)

cmd.Parameters.Add(New OleDbParameter("UserName", _

txtUserName.Text))

Dim saved_hash As String = cmd.ExecuteScalar()

Dim test_hash As String = HashPassword(txtPassword.Text)

conn.Close()

conn.Dispose()

If test_hash = saved_hash Then

MessageBox.Show("Access Authorized")

Else

MessageBox.Show("Get lost, ya bum!")

End If

Private Function HashPassword(ByVal password As String) As _

String

Dim hash As String = ""

Dim i As Integer

For i = 0 To password.Length - 1

hash &= Chr(Asc(password.Substring(i, 1)) + 1)

Next i

Return hash

End Function






Re: Visual Basic General Access server file from client

Khin

hi bruno,

idon know why u give me this code but thanks anywhere.

i found that:

Dim impContext As WindowsImpersonationContext = Nothing
Try
impContext = NetworkSecurity.ImpersonateUser("mydomain",
"bala", "password", LogonType.LOGON32_LOGON_NETWORK,
LogonProvider.LOGON32_PROVIDER_DEFAULT)
Catch ex As ApplicationException
impContext.Undo()
Response.Write(ex.Message)
End Try


can use to solve this problem. but i don know how to define NetworkSecurity and Logon32 and LogonProvider.

Bruno, do u know this

thanks





Re: Visual Basic General Access server file from client

Bruno Yu - MSFT

Khin,

From the code you provide, it seem that you had better use the default LogonProvider when calling advapi.dll. This problem is related to impersonate issue. I strongly recommand you to read the article titled How to implement impersonation in an ASP.NET application:

http://support.microsoft.com/default.aspx scid=kb%3BEN-US%3BQ306158







Re: Visual Basic General Access server file from client

Khin

oh...it looking like needed to use IIS.

em...here i got problem. all of my clients don have IIS.

aih...need to search other way.

thanks bruno