Solving development problems  |  About this blog

Archive for the ‘System administration’ Category

Visual Source Safe Analyze and Repair tool problems

This is the solution if you got this error message when trying to do Analyze and Repair some VSS database using does prompt command:
C:\>”C:\Program Files (x86)\Microsoft Visual SourceSafe\analyze.exe” -F -V3 -D “\\my_server\my_vss_database\data

Error was:

Database analysis in progress File ../data/status.dat is already open Cannot rebuild the database while Visual SourceSafe is being run. Make sure all users have exited SourceSafe and try again.

Solution

Make sure there are no users connected to the VSS database (running ssexp, ssadmin, etc), that users cannot connect to the database using the web service (they connect only for short times, so it’s hard to see them listed as logged in with ssadmin), and that VSS LAN Service is stopped (use net stop ssservice), as it may keep a connection open to the database.

Adding stored JavaScript procedures to MongoDB using Windows Batch script

MongoDB can use stored procedures similar to MSSQL. To make a MongoDB procedure create a new file, name it like DoSomething.js, write a function and attach it to database.

Guide through example

Lets say we have a log of website visitors stored in visitors collection inside myweb database. Each visitors record contains date and time of a visit. Now we want to create monthly statistics – how many users visits website per month.

visitors collection looks like:

> use myweb
> db.visitors.findOne()
{
  "_id": ObjectId("4e0cb7e7da3ea11d18d841e7"),
  "timestamp": "Thu Jun 30 2011 19:52:39 GMT+0200 (Central Europe Daylight Time)"
}

Most reusable way to get data is to create a stored procedure GetVisitsPerMonth() and call it on demand. Create a file GetVisitsPerMonth.js and copy-paste the following code inside. Note that file name is named by procedure.

function ()
{
	var result = db.visitors.group(
	{
		keyf: function(doc)
		{
			return { //NOTE: Bracket must be in this line!!!
				month: doc.timestamp.getMonth(),
				year: doc.timestamp.getFullYear()
			};
		},
		initial: {count:0},
		reduce: function(doc, prev) { prev.count++ }
	});

	return result;
}

How to attach one procedure

Stored procedure can be manually attached like this:

db = connect("localhost:27017/myweb");
db.system.js.save({"_id":"GetVisitsPerMonth", "value": function() { ... });

How to attach multiple procedures

Large sets of procedures should be well organized in files so you can quickly find a procedure and fix it if necessary. To insert or update all procedures at once use a simple batch script.

Create a new file, name it install.bat and copy-paste the following code inside:

@echo off

:parameters
set DBCON=localhost:27017/myweb
set MONGO=c:\mongodb\bin\mongo.exe
set SCRIPT=script.js

:startup
if not exist %MONGO% goto error
if not "%1"=="" goto add

rem Append connection string
echo Adding connection string...
echo db = connect("%DBCON%"); > %SCRIPT%
echo. >> %SCRIPT%

rem Append scripts
call %0 GetVisitsPerMonth
rem call %0 DoSomething
rem other procedures go here

goto install
rem goto end

:add
echo Adding script %1...
echo db.system.js.save({"_id":"%1", "value": >> %SCRIPT%
type %1.js >> %SCRIPT%
echo }); >> %SCRIPT%
echo. >> %SCRIPT%
goto end

:install
echo Running script...
%MONGO% %SCRIPT%
goto end

:error
echo Check if mongo is installed:
echo %MONGO%

:end

Edit parameters according to your needs: path to mongo.exe, database name, and list of procedures.
Simply run the script and it is done.

Testing a stored procedure

Log into mongo console:

> use myweb
> db.eval("GetVisitsPerMonth()")
[
  {
    "month": 5,
    "year": 2011,
    "count": 28233,
  },
  {
    "month": 6,
    "year": 2011,
    "count": 48026,
  },
  {
    "month": 7,
    "year": 2011,
    "count": 92754,
  }
]

Written by developer

October 7th, 2011 at 1:05 pm

Windows 7 – Fix if SLEEP mode does not work

Check your network card properties through the device manager and disable the “Allow this devide to wake the computer” feature.

  1. Right click on your “My Computer” then select Properties.
  2. Click Device Manager on the left side of the Properties window.
  3. Check your Network card on the Network Adapters (Click on the + sign to expand).
  4. Right click on your network card and select properties.
  5. Go to the Power Management tab and untick the option there to prevent your network card from ever waking up your Windows.

Find out what wakes up your Windows 7/Vista from its sleep

To find out what event/device woke up your Windows from its sleep state, go to command prompt (type cmd on the Run/Search box and press ENTER), then type this:
powercfg – lastwake

 

To get the most detailed info (and probably easiest) on the device that wakes your Windows up during the sleep, type:
powercfg –devicequery wake_armed

 

There! You’ll find the culprit I clicked my mouse to wake my Windows up intentionally so that’s why you see an HID compliant mouse on the screenshot above. Yours might be different.

Hope this helps to prevent your computer wakes up from sleep by itself!

If it still doesn’t work:

  • Check out your Power Management Options on your Control Panel (Start, Control Panel, Power Settings, Change plan settings, Change advanced power settings).
    -> “Multimedia settings” option, “When sharing media.” ->”Allow the computer to sleep.
    -> Check other options one by one while you’re at it.

Original article available here.

Written by Avivo

September 11th, 2011 at 9:33 am

Get all project files from Visual Source Safe for a given date

If you are developing some application and use Visual Source Safe as version control software then you probably needed (at least one time) to retrieve all files from your project for specific day from the past.
Visual Source Safe does not allow you to do this from its GUI but there is a DOS command that can help you.

To use the command-line, you must set the Environment Variable for SSDIR to the location of your working SourceSafe database, such as \\Dev1\VSS where Dev1 is the name of the server and VSS is the name of the share where the database is located. You may also need to add ss.exe path to your PATH variable – it is usually in folder: c:\Program Files (x86)\Microsoft Visual SourceSafe\

This is the command:

ss Get "$/your_vss_folder" -R -Vd15-03-2009;2:00a

or just without an hour

ss Get "$/your_vss_folder" -R -Vd15-03-2009
  • First parameter is folder under your Visual Source Safe project
  • -R means to get all files recursively
  • -V means date and in this example we get all files for 15.3.2009

How to block Remote IP address (hacker attack) on Windows 2008 Server?

Block IP address with Windows Firewall 2008

This procedure helped us when someone wanted to hack our server (taken from original post). If you ever feel that someone may be trying to break into your server or know an IP address that you want to block from accessing your server there is a built in firewall on all of our 2008 DDS servers. You can use this firewall to block either a range of IP addresses or a single address.

  1. Log into your server via RDP.
  2. Click on start > administrative tools > windows firewall with advanced security
  3. On the left side of the firewall window click on the inbound rules option.
  4. On the right side of the screen click on New Rule.
  5. Click on the custom radio button and then click next.
  6. Make sure the All programs radio is selected then click next.
  7. On the protocol and ports options leave everything at its defaults and click next.
  8. On the scope screen you will see two boxes the top one is for local IP addresses and the bottom is for remote IP addresses. In this scenario we are trying to block an outside (remote) IP from accessing anything on the server so we will need to add the IP address to this section only as it will not be a local IP address.
  9. Click on the radio that says these IP addresses in the remote section as shown below:
  10. Click on the Add button.
  11. In the next window we will be adding a single IP address to the rule, you can also add an entire range at this point if you wish.
  12. Click ok, click next.
  13. Make sure you select the Block the connection radio on the next screen and then click next.
  14. Leave all of the options on the next screen checked this will be sure to block the IP no matter the connection they are trying to use. Click next.
  15. Name the rule on the next screen something you can remember in case you wish to remove or edit it in the future. Click finish and thats it