Friday, October 19, 2007

Stop or Disable Terminal Server Logons (Change Logon)

Here is a simple command that I had a hard time finding.

Change Logon /Disable
Change Logon /Enable

It prevents users from logging on to the server that the command was ran on. All new connections will be disabled. Existing connections will not be disconnected. So you can run this with remote users logged in to stop new connections while you wait for people to exit.

You can run that from a terminal session. If you get disconnected, you will have to get physical access to the machine to activate it.

From the website: Enables or disables logons from client sessions, or displays current logon status. This utility is useful for system maintenance.

http://technet2.microsoft.com/WindowsServer/en/Library/15a2f502-1fa3-4d3b-a74b-cec04ee52d061033.mspx?pf=true

Running VB.NET code in VBScript or other apps

Here is how you can write a .NET component and use it in a script. First, create a library that contains the code you want to run.

Public Class FileWriter
Public Sub Save(ByVal PathAndFileName As String)
Try
Dim FileStream As New System.IO.StreamWriter(PathAndFileName, False)
FileStream.WriteLine("Hello World")
FileStream.Flush()
FileStream.Close()
FileStream.Dispose()

Catch e As Exception
Dim fs As New System.IO.StreamWriter("C:\error.txt", True)
fs.WriteLine("Exception: {1}", 1, e.Message)
fs.Flush()
fs.Close()
fs.Dispose()
Throw e
End Try

End Sub
End Class


Then compile the library and run regasm c:\project\bin\NameOfDLL.dll /CODEBASE to register it. Regasm is in your .net folder. That will register the dll so you can use it later. Regsvr32 is for non .NET dlls. Your script is next. Save it as a .vbs file.

dim fs
set fs = CreateObject("Project1.FileWriter")
fs.save "c:\file.txt"
set fs = nothing

Anyplace you can call CreateObject, you should be able to use your class. VBA in office is one such place. And I did not test this code, I just gutted another project to have some examples.

Related: Running vbs from .net code

mscorlib: Request for the permission of type Version Culture PublicKeyToken failed.

I wrote a little database access code in vb.net that I wanted to use in another script. I was getting this error though. C:\Test.vbs(6, 1) mscorlib: Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

My dev machine worked fine. And the other box looked like it had the data access and .NET components I needed. Looking closer, it was talking about permissions. The connection string was the same and it contained the password. I decided it was a security zone messing me up.

When I ran regasm, the dll was located on a network share. That was about the only difference. So I unregistered it, moved it locally, and ran regasm again. The problem went away.

mscorlib: Request for the permission of type Version Culture PublicKeyToken failed.

Thursday, October 18, 2007

The system cannot find the file specified. CreateObject

I was attempting to use some vb.net code in a vbs file and was getting "The system cannot find the file specified." on the CreateObject line. I tracked it down to the way I registered the DLL.

One sugestion told me to unregister and re register it with regsvr32. Because I was using .NET, I knew that was not it. It turned out to be my use of regasm to register my DLL. I left out the /CODEBASE option.

Once I registered it with that option, the error went away.

Monday, June 25, 2007

Invalid postback or callback argument.

I was tring to move some web apps to a demo server and ran into this error message on one of them.

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %>in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

what made this move interesting is that the page is a aspx page that was converted from a asp page some time ago and that it was still configured as a dot net 1.1 app in iis. When I moved it, i saw the aspx ending and set it us as a dot net 2.0 app. Changing it back fixed my issus.

I did find this link to a related issue and would have tried those steps if my trick did not work.
http://www.netnewsgroups.net/group/microsoft.public.dotnet.framework.aspnet/topic637.aspx

Friday, April 20, 2007

BACKUP LOG cannot be performed because there is no current database backup

I was getting this message when trying to use a script to back up my database: "BACKUP LOG cannot be performed because there is no current database backup". My searching lead me to this link:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=243166&SiteID=1. where someone else was having the same issue.

The problem happens when you change the database to simple to truncate the log, then back to full recovery. You have to do a manual full backup before you can do a log back up again.

I had gone to simple recovery in an attempt to shrink a log file that was not being maintained.

Migrating SQL Reporting Services 2005

I'm in the process of migrating our production report server and databases into a Virtual PC client to create a Demo machine. This took a lot more steps than I expected.

I installed SQL and Reporting Services. I then tried to back up and restore the report server database and was not having any luck. I later discovered that I need to move both the report server database and the report server temp database.

I used the a script found on MSDN titled Moving a Report Server Database to Another Computer . It looks like it would be found in the SQL Server 2005 Books Online.

This script only works on sql server 2005. There are some new keywords used that 2000 does not support. One key detail was not to use the GUI to back up and restore the databases. Either use a script or detach/reattach the files. The article explains this.

In the configure report server gui, I had to change the credentials type. The default was not working for me. I set it to windows and entered in the account info. connected and applied the changes. If you entered in the wrong password, you will not be alerted to the mistake.

Next step was to restore the encryption key. You will have to export it from the first report server by using the same tool. I was getting this error on the restore: "The encrypted value for the "LogonCred" configuration setting cannot be decrypted". My problem was leaving the password blank on the database set up section.

Once I placed a password in there and gave that account access to the databases, it worked for me.

Another issue I was having was getting the report server initialized. Adding the encryption key solved that.

I then moved over my content, fixed permitions, and changed the datascources. EXEC sp_change_users_login 'Update_One', 'username', 'username' can be an important command to fix logon accounts after a database migration.