|
I am trying to read a simple text file using the following code.
Dim objReader As StreamReader
Dim path As String
path = Me.filePath & "app.dat"
Try
objReader = New StreamReader(path)
objReader.ReadToEnd()
Me.DBUserID = objReader.ReadLine()
Me.DBPassword = objReader.ReadLine()
Me.DBServer = objReader.ReadLine()
Me.webserviceURL = objReader.ReadLine()
objReader.Close()
Catch Ex As Exception
MessageBox.Show("Cannot Read File:" & Me.filePath & " " & Ex.Message & Ex.StackTrace & Ex.Source)
End Try
Seems like it should work but i get a nasty exception that I do not understand.
"Request for the permission type 'System.Security.Premission.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
I have permissions to read or write any file I want in this folder. "C:/myprog/app.dat."
What am I doing wrong and what do I need to do to fix it.
I am using Visual Studio 2005 if that helps.
|
|
|
|
|
The error you're posting doesn't have anything to do with the permissions to the folder you have. It has to do with Code Access Security. Basically, the CODE doesn't have the rights to execute file operations, probably because you launched the .EXE from an untrusted network source.
Now, you have another problem.
objReader = New StreamReader(path)
objReader.ReadToEnd()
Me.DBUserID = objReader.ReadLine()
Me.DBPassword = objReader.ReadLine()
Me.DBServer = objReader.ReadLine()
This code will fail because you opened a file, read it all, then went a tried to read a DBUserID from it. Well, if the file pointer is at the end of the file, how's it supposed to read anything else beyond that? It can't. Remove the .ReadToEnd() line. You don't need it for anything.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
What is the easiest way to check for characters such as . or \ using VB.NET?
CiscoKid55
|
|
|
|
|
Have you looked at the IndexOfAny[^] method of the String class?
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
No but I will check into that.
Thank you
CiscoKid55
|
|
|
|
|
I put this in and it works great!
Thanks
CiscoKid55
|
|
|
|
|
Hi,
I m work in vb6.0 i want insert a special charector in Hirechieachal FlexGrid
for exampal "right mark"
|
|
|
|
|
What do you mean by "insert in a FlexGrid"?
I'm assuming you're talking about a string. You put a special character in a string just like any other character. (Pardon me, but my VB6 is a little rusty)...
Dim newString As String
newString = Left(oldString, 10) & Chr(characterNumber) & Right(oldString, Len(oldString) - 10)
The limitation is that the character you insert must exist in the font that you want the rest of the string to be in. If not, you're pretty much out of luck. You can't use different fonts inside the same string in the FlexGrid.
-- modified at 10:20 Tuesday 1st August, 2006
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi.
I have a web application (RadioBecon) installed on one of the servers. I think it’s written in C# and of course doesn’t have any code behind (so I cannot modify it). The application uses license to track how many people are using it. Every time someone logs in it locks the license in DB. The session, which expires after some time (you can set it in the admin console), is supposed to kick people out and release the license in DB but for some reason it doesn’t do it when session time expires.
I went to wwwroot -> application folder and in the WebConfig file set session to 900 (15 min.). I’ve done that to make sure it kicks people out after 15 min. But that didn’t help either. It does kick people out of application but doesn’t unlock license in the database. I can see in the database user is set as locked. I guess the application is not working right…… Database doesn’t track time and sessions (logins). For reporting purposes to see who’s logged in and for how long the application uses IIS (so no info stored in DB)
The thing is I would like to unlock license of each user after 15 (or any set time) min.
Is there any way for me to write some application (VB.NET) so it can read sessions used in IIS for my application and if they are longer than specified time to remove it and ran SQL query to unlock the user?
Thank you in advance. Alex.
|
|
|
|
|
I'm assuming you know that the session time you set for 900 seconds is the HTTP Session timer. The timer is reset to 900 seconds after each request the user makes.
Your best bet is to contact whoever wrote the application and get it fixed. Unless you know precisely how to unlock the licenses in the database, you're out of luck. No amount of code is going to help you. I don't know of any way that you can force the sessions to timeout using code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
To unlock user licenses is not an issue. I can run SQL statement to do that.
Right now, after session expires, it throws me out of the site but in the database I'm still locked. The problem is that it takes up the license and other people cannot use it until I'm completely unlocked, which we have to do manually.
RadioBeacon is complete app. and I have no code to modify or fix the problem myself. The RadioBeacon guys want us to upgrade to new version, they say it will fix the problem + more. But we have $20,000 worth of customizations, which we will lose by moving to new version.
Is there anyway I can access IIS on the server for RadioBeacon and see all the existing sessions (and values)? If the session state is more that 15 min I will run SQL statement to unlock license and kick user out, and of course destroy session.
Thank you,
|
|
|
|
|
alexfromto wrote: Is there anyway I can access IIS on the server for RadioBeacon and see all the existing sessions (and values)?
Like I said, not that I know of.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Yeah, but none of that exposes any access to a web site's Session Manager. You can set timeout values for the site, but you have no access to the individual sessions.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Yeah. You know what? The RadioBeacon has a User Report that actualy shows who's signed in and for how long. I wonder how they did it...
Thanks,
|
|
|
|
|
It's real easy to have the site store its session data in a table in the SQL server...
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
vb.net
i have a form with some textboxes connected to my access-database.
when i change the text in one of the boxes, and click the update-button,my database is updated and everything is fine.
now i have an openfiledialog. the file (jpg, gif, bmp) that's selected in that dialog is shown in a picturebox. thsi has nothing to do with my database.
but whenever i open the dialog, i can't update my database any more afterwards and visual studio stops my program with some error message (i think it was, when oledataadapter was updated with datasource)
when i don't open the dialog everything works fine.
what's goin wrong? what can i do?
|
|
|
|
|
This is caused by several problems. Not the least of which is that your connection string is not using a fully qualified path to the database file. You probably have something like:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydb.mdb
Right?
What you're doing is assuming that the database is in the current directory. The current directory can change at any time, like you've found out while using the OpenFileDialog.
Now, when the current directory changes, your next connection to the database fails because the .MDB file is no longer in the current directory. The correct way to do any kind of file access is to always specify fully qualified path names to your files, including inside connection strings. This way, none of your file access depends on the current directory being what it's supposed to be.
Public Shared Function GetConnectionString(ByVal databaseFilename As String) As String
' Build the fully qualified path to the file in the .EXE's startup folder.
Dim fp As String = Path.Combine(Application.StartupPath, databaseFilename)
Dim cs As String = String.Empty
' Check if the file exists...
If File.Exists(fp) Then
' If so, build a connection string with it...
cs = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", fp)
Else
' If not, throw an exception...
Throw New FileNotFoundException("The database file " & databaseFilename & " cannot be found in the application startup directory!")
End If
' Return the completed connection string.
Return cs
End Function
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thank you very much, i will try this later.
|
|
|
|
|
Hellow to all
i am trying to attatch a HScrollbar to a PictureBox or to a form . i am useing drawing method in the PictureBox that i don't wanna lose the painting inside them ..
thxx ..
|
|
|
|
|
microuser_2000 wrote: i am useing drawing method in the PictureBox that i don't wanna lose the painting inside them
I fail to see how a ScrollBar is going to accomplish this. How about explaining what you really trying to do and what your problem is.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
the thing is like that i have my picture box that i had in it information for this example stations names , but in some cases i have a plenty of station that wont fit all in the same picture box , so what i need is to scroll and go to the right and read the whole information ...
that's why i need scroll in my picture box ..
thank u ..
|
|
|
|
|
I have no idea how your putting this information in the picturebox, but there's an easy solution. Resize the picturebox to as big as you need it, then put it inside a Panel control and set the Panel's AutoScroll property to True. Done!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Good Morning!
Wondering if anyone could enlighten me and possibly share some code as to how to report the install status of a specific update based on it's ID (ie: MS06-035 id:5915bac3-4cbd-4e1b-9ff1-8adc4188dd22) in VB.NET using the WSUS api.
Any help would be appreciated.
JCO
|
|
|
|
|
i work in database sql server 2000 and i need to encrypt password column so that and body open data base can not read passord
what code i use to do this
ma_refay
|
|
|
|