10 lessens about T-SQL
Archiv podle štítků: SQL
SQL 2008 R2 : error 18401
After install Service Pack and Cummulative Update and restart server I got this message:
Login failed for user '<Domain Name>\<user name>'. Reason: Server is in script upgrade mode. Only administrator can connect at this time. (Microsoft SQL Server, Error: 18401)
Don’t panic, you must only wait few minutes
SQL Express – backup s notifikací
Tento skript uložit jako SQL soubor a naplánovat automatické spouštění pomocí Windows. Na posílání emailu jsem použil vytvořenou proceduru pomocí http://www.mssqltips.com/tip.asp?tip=1795
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | DECLARE @databasename AS VARCHAR(2048) DECLARE @backupfile AS VARCHAR(2048) DECLARE @backupname AS VARCHAR(2048) DECLARE @backup AS VARCHAR(2048) DECLARE @recipients AS VARCHAR(2048) --- SETTINGS VARIABLE --- SET @databasename = 'BW_DEMO' SET @backupfile = 'E:\BackupSQL\BACKUP_BW_DEMO.BAK' SET @backupname = @databaseName + '-Full' SET @recipients = 'info@domena.cz' BACKUP DATABASE @databasename TO DISK = @backupfile WITH NOFORMAT, INIT, NAME = @backupname, SKIP, NOREWIND, NOUNLOAD, STATS = 10 DECLARE @nowdate AS VARCHAR(2048) SELECT @nowdate = CONVERT(VARCHAR(10), GETDATE(), 120) + '%' USE msdb DECLARE @resultcount AS INT SELECT @resultcount = COUNT(*) FROM dbo.backupset WHERE CONVERT(VARCHAR(10),backup_start_date,120) LIKE @nowdate AND name = @backupname AND database_name = @databasename DECLARE @emailbody AS VARCHAR(2048) DECLARE @subject AS VARCHAR(256) IF @resultcount=0 BEGIN SET @subject = 'BACKUP ' + @databasename + ': FAILED.' SET @emailbody = 'BACKUP ' + @databasename + ' IS FAILED.'; END ELSE BEGIN Declare @result table ( ID INT IDENTITY(1,1), backup_size int, backup_start_date DATETIME, backup_finish_date DATETIME ) insert into @result(backup_size,backup_start_date,backup_finish_date) select backup_size,backup_start_date,backup_finish_date FROM dbo.backupset WHERE CONVERT(VARCHAR(10),backup_start_date,120) LIKE @nowdate AND name = @backupname AND database_name = @databasename DECLARE @id AS INT DECLARE @text AS VARCHAR(2048) DECLARE @set AS VARCHAR(2048) DECLARE @start AS DATETIME DECLARE @stop AS DATETIME SELECT @set = '' SELECT @id = 1 WHILE @id < = @resultcount BEGIN SELECT @text = backup_size FROM @result WHERE id=@id SELECT @set = @set + 'Size backup: ' + @text + 'B<br>' SELECT @start = backup_start_date FROM @result WHERE id=@id SELECT @set = @set + 'Start time: ' + CONVERT(VARCHAR(20),@start,13) + '<br />' SELECT @stop = backup_finish_date FROM @result WHERE id=@id SELECT @set = @set + 'Total time: ' + CONVERT(VARCHAR(100),DATEDIFF (second,@start,@stop),8) + ' seconds' + '<br />' SELECT @set = @set + '<br />' SELECT @id = @id + 1 END SET @subject = 'BACKUP ' + @databasename + ': SUCCESSFUL' SET @emailbody = 'BACKUP <b>' + @databaseName + '</b> IS SUCCESSFUL.<br />' SET @emailbody = @emailbody + 'File backup: ' + @backupfile + '<br /><br />More information:<br />' + @set END EXEC spSendMail @recipients = @recipients, @subject = @subject, @from = 'sql@domena.cz', @body = @emailbody GO |
Reporting Services 2005 na Windows 2008 R2
Pár odkazu na které jsem narazil při řešení problémů:
http://support.microsoft.com/kb/934164/en-us
http://blogs.technet.com/b/keithward/archive/2009/01/02/reporting-services-2005-setup-on-vista-windows-2008.aspx
Jak zapnout povoleni zobrazeni chyby
Spustit na SQL kde je Reportiong Services
1. Create a text file and copy the following script into the file.
Copy
Public Sub Main()
Dim P As New [Property]()
P.Name = „EnableRemoteErrors“
P.Value = True
Dim Properties(0) As [Property]
Properties(0) = P
Try
rs.SetSystemProperties(Properties)
Console.WriteLine(„Remote errors enabled.“)
Catch SE As SoapException
Console.WriteLine(SE.Detail.OuterXml)
End Try
End Sub
2. Save the file as EnableRemoteErrors.rss.
3. Click Start, point to Run, type cmd, and click OK to open a command prompt window.
4. Navigate to the directory that contains the .rss file you just created.
5. Type the following command line, replacing servername with the actual name of your server:
Copy
rs -i EnableRemoteErrors.rss -s http://servername/ReportServer
Missing SQL performance counters
- Stop SQL Server Service
- Open Command Prompt (Start ? Run ? Cmd)
- Run the command: NET STOP MSSQLSERVER
- Then, this question will appear: ?The following services are dependent on the SQL Server (MSSQLSERVER) service. Stopping the SQL Server (MSSQLSERVER) service will also stop these services: SQL Server Agent (MSSQLSERVER). Do you want to continue this operation? (Y/N) ?
- Press ?Y?
- Open Command Prompt and get located on the BINN directory of SQL Server. Probable locations are:
- x:\Program Files\Microsoft SQL Server\90\Tools\Binn
- x:\Program Files\Microsoft SQL Server\80\Tools\BINN
- Once located on the BINN directory, using the Command Prompt, execute the following command: lodctr sqlctr.ini
- Restart your computer.
Testovací databáze
Pokud potřebujete testovací databázi pro MS SQL, je možné si ji zde stáhnout : http://msftdbprodsamples.codeplex.com/.