Kayıtlar

SQL etiketine sahip yayınlar gösteriliyor

SQL Server Database Snapshot

Merhabalar , Database Snapshot özellikleri SQL 2005 'den itibaren bizlerin kullanımına sunulan çok sevdiğim özelliklerden birisi. Kısaca DataBase Snapshot , Veri tabanın o anda bir resmini çekmeye benzer. Veri tabanın Snapshot oluşturduğu andan itibaren elimizde read-only bir kopyasını elde etmiş oluruz. Temel amacı ise Asıl veri tabanımızda ,snapshot oluşturulduğu andan sonra, değiştirilmiş kayıtların orjinal hallerini saklayıp gerektiğinde düzeltmektir. İsterseniz örnek bir senaryo ile daha iyi anlıyalım, daha sonra da olumlu ve olumsuz yanlarından bahsedelim. CREATE DATABASE  CUSTOMER_SS_CASE1  ON  ( NAME  = CUSTOMER, FILENAME =  'C:\SQLDATA\CUSTOMER_SS_CASE1.SS' ) AS  SNAPSHOT OF CUSTOMER; Senaryomuz'da Customer veritabanın da önemli değişiklik planlıyoruz. 3 farklı case den oluşan değişikliğin ilk adımında belirtilen dosya altına Veritabanımızın o andaki snapshot'nı aldık. Şu andan itibaren yapılan tüm update,delete,insert işlemleri öncesinde ,orjinal halleri s

Lock Request time out period exceeded Error 1222

  Bu hatayı, SSMS açmaya çalışırken (Tabloları,sp,view vs. görüntülemek adına) zaman zaman karşımıza çıkabilir. Sebebi ise o anda sistemi kilitleyen ciddi olabilecek bir işin çalışması yada açık transaction bırakıp lock koyması olabilir.    Bunun için şu dmv ler ile neler oluyor bakabiliriz. select   distinct   object_name ( a . rsc_objid ), a . req_spid , b . loginame from   sys . syslockinfo  a   ( nolock )   join   sys . sysprocesses  b   ( nolock )   on  a . req_spid = b . spid where   object_name ( a . rsc_objid )   is   not   null    Bu query hangi tablo lock almış, proccesID ve LoginName, neyi tutuyor bunu görebiliriz.Daha sonra doğru proccesi bulup kill edersek sorunu çözmüş oluruz.  

Kullanıcılara Ms Sql Server Agent Jobs Yetkileri Dağıtma

Ms-Sql Server yönetimi yaparken tabi ki veritabanlarımız olacak. Bu veritabanlarına ait kullanıcılarımız olacak. Bu kullanıcılar da tabi ki server üzerinde yetkisiz olacaklar (genellikle). Veritabanlarının üzerinde belirli zamanlarda yapılması gereken işleri olacak. Bu işler agentla yapılacak. Tabi ki bu job’ları kullanma yetkisi istenecek. Server üzerinde sysadmin vermeden hangi hakları sql user’lara sağlarsak bu istekleri karşılayabileceğiz? Ms-Sql Server üzerinde Agent’ın msdb üzerinde verdiğimiz üç çeşit hak ile Agent Security’yi düzenleyebiliyoruz. Bu haklar şöyle: SQLAgentUserRole SQLAgentReaderRole SQLAgentOperatorRole Kısaca bu roller, User kendi joblarını oluşturma, silebilme, çalıştırabilme, düzenleme hakkıdır. Reader multiserver üzerinde bu haklara sahip olmasıdır. Operator server üzerindeki diğer jobları da yönetebilmesidir. ( Ayrıntılı bilgi için ) Bu hakları vermek için Security sekmesi açılır Login genişletilir Yetki vermek istediğimiz kullanıcı sağ tıklanır

MSSql & WSUS: Database cannot be opened. Marked as suspected

Hi, the WSUS DB (MSSQL Express 2005) of a customer won’t start after a hardware failure and bluescreen. Here are the steps which recovers the database back in an usable state. The SQL Server Instance logs errors like this "Could not redo log record (183366:6166:54), for transaction ID (0:117029942), on page (1:657511), database 'SUSDB' (database ID 5). Page: LSN = (183267:2976:260), type = 2. Log: OpCode = 2, context 3, PrevPageLSN: (183366:1717:287). Restore from a backup of the database, or repair the database." in  “C:\Windows\SYSMSI\SSEE\MSSQL.2005\MSSQL\LOG\ERRORLOG”  and the database is down. First connect to the DB Instance using a named pipe c:\> sqlcmd -S np:\\.\pipe\MSSQL$MICROSOFT##SSEE\sql\query and see state of the Database. Replace SUSDB with the Databasename of your DB. Try to repair the Database. The repair attempt fails… DBCC CHECKDB ('SUSDB') WITH NO_INFOMSGS, ALL_ERRORMSGS; go Error MEssage: Database ‘SUSDB’ cannot be opened

Shrink Database Log files (Full recovery mode)

USE Database_name; GO – Truncate the log by changing the database recovery model to SIMPLE. ALTER DATABASE Database_name SET RECOVERY SIMPLE; GO – Shrink the truncated log file. DBCC SHRINKFILE (Database_name_log); GO – Reset the database recovery model. ALTER DATABASE Database_name SET RECOVERY FULL; GO

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider did not give any information about the error.

Exec sp_configure ' show advanced options' , 1; RECONFIGURE; GO   Exec sp_configure ' Ad Hoc Distributed Queries' , 1; RECONFIGURE; GO   EXEC master.dbo.sp_MSset_oledb_prop N ' Microsoft.ACE.OLEDB.12.0' , N ' AllowInProcess' , 1; GO EXEC master.dbo.sp_MSset_oledb_prop N ' Microsoft.ACE.OLEDB.12.0' , N ' DynamicParameters' , 1; GO   Insert into OPENDATASOURCE ( ' Microsoft.ACE.OLEDB.12.0' , ' Data Source=C:\upload_test.xlsx;Extended Properties=Excel 12.0' )...[Sheet1$] SELECT ColumnNames FROM Your_table -- Sheet Should be already Present along with headers EXEC master.dbo.sp_MSset_oledb_prop N ' Microsoft.ACE.OLEDB.12.0' , N ' AllowInProcess' , 0; GO EXEC master.dbo.sp_MSset_oledb_prop N ' Microsoft.ACE.OLEDB.12.0' , N ' DynamicParameters' , 0; GO   Exec sp_configure ' Ad Hoc Distributed Queries' , 0; RECONFIGURE; GO   Exec sp_configure ' show advance

View and Edit Two Files Side By Side in SQL Server and Notepad++

Resim
Notepad++ is the editor that programmers prefer most because it is fast and lightweight. It is also bundled with tons of features and smart plugins. Notepad++ can be downloaded for free and is available on Windows as well as other operating systems. There are various tips and tricks that you can use to increase your productivity with Notepad++. One of the coolest tricks is viewing and editing two files side by side. Use the following steps to view two files side by side in Notepad++. 1. Open both the files you want to view simultaneously with Notepad++. 2. Right-click on any one of the  file tabs , and click  Move to Other View . 3. After you have viewed the two files side by side, you can go back to the previous tabbed view by right-clicking on the file and then clicking on Move to Other View. This will give you the normal document view of the files. In SQL Server, you can open two scripts at the same time either vertically or horizontally. This makes it easier to v

Script to retrieve SQL Server database backup history and no backups

Resim
Problem There is a multitude of data to be mined from within the Microsoft SQL Server system views.  This data is used to present information back to the end user of the SQL Server Management Studio (SSMS) and all third party management tools that are available for SQL Server Professionals.  Be it database backup information, file statistics, indexing information, or one of the thousands of other metrics that the instance maintains, this data is readily available for direct querying and assimilation into your "home-grown" monitoring solutions as well.  This tip focuses on that first metric: database backup information.  Where it resides, how it is structured, and what data is available to be mined.  Solution The msdb system database is the primary repository for storage of SQL Agent, backup, Service Broker, Database Mail, Log Shipping, restore, and maintenance plan metadata.  We will be focusing on the handful of system views associated with database backups for this tip:

How to reset the SA password in SQL Server

Resim
Getting locked out of a SQL Server can happen in a number of ways.  You could inherit a server that was managed by someone that left the company and only that person had System Admin rights for example. A recent encounter I had was were a database server was built and provisioned in one active directory domain and then moved and joined to another non trusted domain. All the accounts provisioned within the server include those for the DBA admins were basically useless since they couldn’t be authenticated.  The built in SA account is locked down per policy so no one knows the password. What do you do if you find that you are locked out of a SQL Server instance? The way I handle it is to start SQL Server in single user mode, launch SQLCMD and create a new user. I then still using SQLCMD grant the new user the system admin role.  Once I have the new user created I restart SQL Server Service and log in using the new credentials. I can then clean up the instance by granting proper access.

Solution: SQL Server Enterprise Manager General OLE Error 16386

Tried to start Microsoft SQL Server Enterprise Manager and got stuck at the error message  General OLE Error 16386 : try this, maybe this solves the issue.. a. Stop all SQL Server services (MSSQLServer, SQLServerAgent, MSSEARCH) b. Open command prompt and go to the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn directory c. Unregister the following .dll files (Ex. regsvr32 /u dtsui.dll): dtsui.dll,sqlns.dll, sqldmo.dll, sqllex.dll, sqlmmc.dll d. Copy and paste the .dll files from a CD (under x86\Binn directory) to the Program Files\Microsoft SQL Server\80\Tools\Binn e. Register the .dll files (Ex. regsvr32 sqldmo.dll)

Truncate Logfile in SQL Server

Using the code Step 1. Copy/type the below given SQL. Step 2. Change @DBName to < Database Name>, @DBName_log to Step 3. Execute the SQL. ALTER DATABASE @DBName SET RECOVERY SIMPLE WITH NO_WAIT DBCC SHRINKFILE(@DBName_log, 1) ALTER DATABASE @DBName SET RECOVERY FULL WITH NO_WAIT GO In SQL Server data is stored using two physical files:  (.mdf)  extension  which contains the data.  (.ldf) extension which contains log. Log file size increases very rapidly and depend on the operation performed on the data. After a long time period this file becomes too large. When log file is too large it takes time to perform some operations like ( attach , de-attach, backup, restore … etc ). 

SQL: List Database Connections for specific user

Code (SQL Statement) starts here select * from master..sysprocesses where loginame = ‘connexin.cim’ –and hostname=’COMPUTERNAME’ order by hostname Code (SQL Statement) ends here

SQL: Drop / Kill Database Connections

If you need to drop database connections for a specific database, go read on..  This has been tested for Microsoft SQL Server 2005 and Microsoft SQL Server 2008. Code starts here use master declare @vcdbname varchar(50) /* @vcdbname => set it to the database you want the connections to be dropped.. */ Set @vcdbname = ‘cxnIM’ set nocount on declare Users cursor for select spid from master..sysprocesses where db_name(dbid) = @vcdbname declare @spid int, @str varchar(255) open users fetch next from users into @spid while @@fetch_status <> -1 begin    if @@fetch_status = 0    begin    print @spid       set @str = ‘kill ‘ + convert(varchar, @spid)       exec (@str)    end    fetch next from users into @spid end deallocate users and ends here

How to Migrate Microsoft SQL Server to MySQL Database

Resim
If you are using mostly open source in your enterprise, and have few MS SQL server database around, you might want to consider migrating those to MySQL database. The following are few reasons why you might want to consider migrating Microsoft SQL Server to MySQL database: To avoid huge License and support fees of MS SQL Server. In MySQL, even if you decide to use the MySQL enterprise edition, it is less expensive. Unlike SQL Server, MySQL supports wide range of Operating Systems including several Linux distros, Solaris and Mac. To implement a highly scalable database infrastructure To take advantage of several advanced features of MySQL database that have been tested intensively over the years by a huge open source community We can migrate MS SQL database to MySQL using migration module of “MySQL Workbench” utility. The most easiest way to install MySQL Workbench is to install “Oracle MySQL installer for windows”, which installs several MySQL tools including the Workbench

SQL Server Auditing

SQL Server da auditing işlemini profiler arayüzü ile yapabiliyoruz. Tüm hareketleri, ilgili kriterleri seçerek (Örn.: Login/Logout, database operation vs.) oluşturulan trace altında toplayabiliriz. SQL server bu trace leri sp_trace_setevent adı alında konfigure etmekte, trace id ve event id lerin ne anlama geldiklerini aşağıdaki Microsoft linkten ulaşabiliriz. http://msdn.microsoft.com/en-us/library/ms186265.aspx SQL SERVER AUDITING Şimdi aşağıda hazırlanmış default olarak nitelendirdiğim bir query i paylaşıyor olacağım. /****************************************************/ /* Created by: SQL Server 2008 Profiler (Anatoli) */ /* Date: 01/05/2011 11:43:53 AM */ /****************************************************/ -- Create a Queue declare @rc int declare @TraceID int declare @maxfilesize bigint set @maxfilesize = 20 -- Please replace the text InsertFileNameHere, with an appropriate -- filename prefixed by a path, e.g., c:\MyFolder\MyTrace. The .trc extension -- will be appended to th

Sql serverda protokoller

Sql Server’ın hangi protokolleri dinleyebildiğini görmek için, SQL Server Computer Manager’ı açın. Server Network Configuration altındaki Protocols for MSSQLSERVER ağacını açtığınızda, aktif olan protokeller bu şekilde karşınıza gelecektir. Varsayılan olarak, sadece Shared Memory aktiftir. SQL Server’ın versiyonuna ve kullanılan işletim sistemine bağlı olarak, eski versiyonlarda farklı NetLibs’ler varsayılan olarak aktif edilmiştir. SQL Server’a uzaktan (Web server yada farklı uzak istemcilerden) erişebilmek istiyorsanız buradaki NetLibs’lerden birini aktif etmeniz gereklidir. (TCP/IP ile ilgileniyorsanız, IP NetLib’in varsayılan port numarası 1433 ‘dür. ) Unutmayın ki, istemcinizin server ile bağlantı kurabilmesi için, server’ın istemcinin kullandığı port ile aynı port üzerinde, istemcinin kullandığı protokolü dinliyor olması gerekir. Bu nedenle, Named Pipes ortamındaysak, yeni bir kütüphane eklememiz gerekebilir. Bunu yapmak için, Protocols ağacına geri dönüp Named Pipes protokolüne