czwartek, 23 grudnia 2010

Connecting to different SQL Server (T-SQL)

If you working on one database and you want to do something on another database you have to create a linked server. To create linked server use sp_addlinkedserver stored procedure (more info)



EXEC sp_addlinkedserver
@server = 'linkedServerName',
@srvproduct = '',
@provider = 'MSDASQL',
@provstr = 'DRIVER={SQL Server};SERVER=servername\instancename;DATABASE=databeseName;UID=login;PWD=password;';

After you executed obove query you can check if linked server was added correctly. Using sp_linkedservers sp you should see :



Now you can quering linked server, for example :


select * FROM linkedServerName.master.dbo.sysdatabases

If you want to call remotly stored procedure you must execute these two statments too :


exec sp_serveroption @server='linkedServerName', @optname='rpc', @optvalue='true'
exec sp_serveroption @server='linkedServerName', @optname='rpc out', @optvalue='true'

wtorek, 6 kwietnia 2010

Replacing windows notpad with notpad2

Is simple way to replace windows notepad with notepad2 (4.1.24 or newer), you have to create and run that script batch:


reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v "Debugger" /t REG_SZ /d "\"%~dp0Notepad2.exe\" /z" /f