Showing posts with label batch. Show all posts
Showing posts with label batch. Show all posts

Tuesday, March 30, 2010

IPV6 Configuration Script

copy and paste the following into 2 *.bat files.

RestoreIPV6Configuration.cmd:
*************************************************************
@echo off

set DumpLocation=%1

if exist %DumpLocation%\isatap.dump (
netsh interface isatap set state default
netsh -f %DumpLocation%\isatap.dump
)

if exiSt %DumpLocation%\6to4.dump (
netsh interface 6to4 set state default
netsh -f %DumpLocation%\6to4.dump
)
exit 0
*************************************************************

DisableIPV6Protocols.cmd
*************************************************************
@echo off

set DumpLocation=%1

netsh interface isatap dump state > %DumpLocation%\isatap.dump
netsh interface isatap set state disabled
netsh interface 6to4 dump state > %DumpLocation%\6to4.dump
netsh interface 6to4 set state disabled
exit 0
*************************************************************

Saturday, November 28, 2009

write setup batch file based on processor architecure

take the following lines put it into a *.bat file and based on your OS the correct setup will be started.

@echo off
if /i "%PROCESSOR_ARCHITECTURE%" == "X86" "%~d0%~p0\x86\setup.exe"
if /i not "%PROCESSOR_ARCHITECTURE%" == "X86" "%~d0%~p0\x64\setup.exe"

Monday, October 20, 2008

Backup and Restore Database for SQL Server

@echo off
@echo BatchJob Start
@echo %date% %time% %0 Start >> ".\!Log\all.log"
@echo on

"Start backup database DISK='%cd%\ABC.bak'" >> ".\!Log\all.log"
osql /E /S localhost /Q "backup database DISK='%cd%\ABC.bak'"
"c:\Program Files\WinRAR\winrar" a ABC.rar erp.bak -df -ibck
"Done backup database DISK='%cd%\ABC.bak'" >> ".\!Log\all.log"

REM NOW WE RESTORE IT

"Start restore database DISK='%cd%\ABC.bak'" >> ".\!Log\all.log"
osql /E /Q "restore database ERP from DISK='%cd%\ABC.bak'"
"Done restore database DISK='%cd%\ABC.bak'" >> ".\!Log\all.log"

@echo off
@echo %date% %time% %0 End >> ".\!Log\all.log"

Saturday, October 18, 2008

ORM (Object Relational Mapper) - what is available

Once you get familiar with ORM's you will "Love or Hate" the idea.

For a new project I write I decided to use once more an ORM Tool. There are so many ORM's outside there and because I develop it only in .Net C# and I love the idea for open source I decided I only go for an open source object relational mapper.

Microsoft comes out with some stuff called "Linq to SQL" and "Entity Framework". I could find lot of information about it but in the end I could NOT find a really working solution which is based on a n-tier architecture. Since my point of view is that applications are also applications which are based on different tiers or models I'm not satisfied with this "0815 / drag & drop" Microsoft solutions which are done in 5 minutes.

An application has to be divided into various tiers. Lets say it simple:
- Data Access Layer
- Business Object Layer
- Presentation Layer

if you need more well done but I prefer a clean architecture instead of one Website Project which contains a mix of anything. Can be that for other people it is good enough. Anyway, enough about my personal point of view.

Following criteria are important to me:

  • Perspective on Performance
  • Perspective on Data-source independence - access various data-sources SQL Server, OBDC etc.
  • Perspective on Lazy Load of parent entities
  • Perspective on Pluggable Creation Mechanism
  • Perspective on Separation Of Tiers And Layering Preferences
  • Perspective on Transactions Control
  • Perspective on Mapping (1:1, 1:N, N:M)
  • Perspective on Query Facilities
After many hours of researching, downloads, testings and clarifications I come up with the following list which could be interesting. Please note the notes beside are my personal point of views and does not need to match anything other opinion.

Notice: if you have an actual ORM mapper which is not listed above post them please (Only Open Source Projects please and no shareware - comments with links to shareware application will not be approved!!).

Tuesday, July 24, 2007

How To: Shrink Sql Server 2005 Log Files

Shrink Sql Server 2005 Log Files




use YourDbName
backup log YourDbName with truncate_only
dbcc
shrinkfile(YourDbName_log)

if you copy your databases, names are not always the same! based on how do you copy it it still has the same name like the source database.. keep attention when you run it - then it shrinks e.g. 130 GB -> 22 MB .... many information goes away.

Update:

========

today i done some researches and I found the following thread:

http://www.eggheadcafe.com/software/aspnet/30488923/script-which-will-shrink.aspx

after some analyzing and test runs the follwoing solution worked for me:


CREATE TABLE #TDatabases(
DBName nvarchar(128),
DBLogicalName nvarchar(128)
)
INSERT INTO #TDatabases
SELECT db.name DBName, mf.name DBLogicalName
FROM sys.databases db join sys.master_files mf
on db.database_id = mf.database_id
WHERE db.name not in ('master', 'tempdb', 'model', 'msdb',
'distribution') AND type_desc LIKE 'log'

SET NOCOUNT ON
DECLARE @VarDBLogicalName nvarchar(128)
DECLARE @VarDBName nvarchar(128)
DECLARE @VarRowCount int

SELECT top 1 @VarDBName = DBName, @VarDBLogicalName = DBLogicalName
FROM #TDatabases
SET @VarRowCount = @@rowcount
WHILE @VarRowCount <> 0
BEGIN
EXEC(' use ' + @VarDBName + ' backup log '+ @VarDBName + ' with no_log
dbcc shrinkfile(''' + @VarDBLogicalName + ''', TRUNCATEONLY) WITH
NO_INFOMSGS')
DELETE
FROM #TDatabases
WHERE DBName = @VarDBName
SELECT top 1 @VarDBName = DBName, @VarDBLogicalName =
DBLogicalName
FROM #TDatabases
SET @VarRowCount = @@ROWCOUNT
END
DROP TABLE #TDatabases
SET NOCOUNT OFF


(otherwise search at google for: "osql shrink all db" in it doesn't fit your needs)


the above script you put now simply into a *.sql file (e.g.: shrinkalldatabases.sql).

now you need to create a second, which is simply a batch file (e.g.:startshrink.cmd) : *.bat or *.cmd. Into this file you write the following command:

osql -E -i shrinkalldatabases.sql -o result.txt

more info about osql you can find here: http://technet.microsoft.com/en-us/library/aa213088(SQL.80).aspx

all needed parameters are the following:

-E -> authentication
-i -> input file
-o -> output file

once you add it now to run once a week you have no further problems with your sql db sizes :-)

to have a small history and some additional information, here how I have created my *.cmd file:

@echo start: %date% %time% >> result.log
osql -E -i shrinkalldatabases.sql >> result.log
@echo end: %date% %time% >> result.log

enjoy it.



Monday, February 19, 2007

How To: Execute a Batch file within Winform

just some code, I don't think there is to much to explain.

Copy & Paste it:



string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase).Replace(@"file:\", "");
// get some key from the config file.
string serviceIp = COM.Handler.Config.GetStringValueFromConfigByKey("IpAddress");
string vars = " " + serviceIp;

Process proc = new Process();
// attach the file
proc.StartInfo.FileName = @"YourBatchFile.cmd";
// pass arguments
proc.StartInfo.Arguments = vars;
// hidden run
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
// no need in my case for show errors.
proc.StartInfo.ErrorDialog = false;
// set the running path
proc.StartInfo.WorkingDirectory = path;
// start the process
proc.Start();
// wait until its done
proc.WaitForExit();
// any other number then 0 means it is an error.
if (proc.ExitCode != 0)
MessageBox.Show("Error executing in YourBatchFile.cmd", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);


hope this helps.

Tuesday, January 16, 2007

install Webpart dll's into your MOSS Server GAC with a simple VS post-build event

after many different tries how to automate that local deployment from the Win XP machine to my MOSS 2007 Development Server instance i figured out my way how to do this:

- Build your solution and your DLL is deployed :-)

that's all. I think that's pretty cool.

so how you do it:

- download PsExec v1.73
- create 2 batch files (*.bat or *.cmd)

- Batch No. 1: run's as post build event of your compilation

- this file should include the following steps:
1. receives as argument the dll full path and just the dll name;
e.g:
Arg 1: C:\MyProjects\VisualStudioSolution\Moss\indexus.net.dll
Arg 1: indexus.net.dll
2. you copy your arg 1 to a share on your server
2. you call your batch no. 2 with arg 2

- Batch No. 2: run's as remote batch file over psExec.

- don't forget that psExec is running like a local command line
on your server, you need to know where you have call it.

- C:\cmd\psExec.exe -d \YourServerName C:\YourServerShare\[arg no.2]

hope this helps!

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge