October 22, 2011 06:47 by
Scott
This is great for developers, testers, and anyone looking to learn Active Directory or deploy to a small network. If this is for a production deployment, you might want to bring in a professional to help you. There are many other things to consider, like ‘hardening’ your server and setting up Group Policy. Having an insecure or unprotected domain controller is inviting havoc on your network.
So without any further ado and in the immortal words of ‘Marv’, “Let’s get to it!”
In the Server Manager click on Add Roles.
Click next on the ‘Before You Begin’ screen if it shows. On the next screen, ‘Select Server Roles’, check the box for Active Directory Domain Services. After checking the box, you may receive a window that says you need to add required features, click the button marked Add Required Features.
Then back at the ‘Select Server Roles’ window, click Next. Here you can do some reading if you’re unfamiliar with Active Directory. There are links for an overview, installation instructions, and common configurations. There’s also some notes that say it is advisable to have at least 2 domain controllers, that you’ll need a DNS server, that you’ll have to run DCPROMO.exe, and informs you that you’re also installing DFS (Distributed File System), and some replication services tied to DFS.
Click Next and you’ll see the ‘Confirm Installation Selections’ window. Click the button marked Install.
The ‘Installation Progress’ window will appear letting you know what the system is doing. After a few minutes the ‘Installation Results’ window will appear. Click the link marked Close this wizard and launch the Active Directory Domain Services Installation Wizard (dcpromo.exe).
Another wizard will open, ‘Active Directory Domain Services Installation Wizard’. Click Next
Read the note on the next screen titled ‘Operating System Compatibility’. The link to the KB article 942564 underneath is (http://go.microsoft.com/fwlink/?LinkId=104751). Click Next. On the ‘Choose a Deployment Configuration’ screen, we’ll choose Create a new domain in a new forest for the purposes of this tutorial. If you’re attempting to add a domain controller to an existing domain / forest, you would choose the ‘Existing Forest’ checkbox. Click Next
Here’s where you input what you want your FQDN (Fully Qualified Domain Name) to be. Then click Next.
The system will confirm that the FQDN is not in existence already on your network, then allow you to choose your Domain NetBIOS name. After doing so, click Next. The system will then confirm that NetBIOS name is not in use.
On the next screen, you select what you want your forest functional level to be. You can choose: Windows Server 2003, 2008, or 2008 R2. In this tutorial we’ll be setting the forest functional level to Windows Server 2008 R2. If you’ll be connecting other DCs that are running Windows Server 2008 or 2003, then may will need to choose a compatible level. Click Next.
Now we’ll install the DNS server. Make sure that DNS server checkbox is checked, then click Next. Domain controllers, DCs, require Domain Name Services.
Click Yes at the next window, which is warning you that delegation cannot be configured for the parent zone. Don’t worry, there is no parent zone. Accept the default locations for your Database, Log Files, and SYSVOL folders, or change them if you really like. Click Next.
Input a password, twice, in the ‘Directory Services Restore Mode Administrator Password’ window. Then click Next. Review your selections and click Next.
The wizard will then install and configure Active Directory Domain Services and Directory Services on the DC. Click Finish, and select to Restart.
Congratulations, you’ve just done the basic setup for an Active Directory Domain Controller, and DNS support services on Windows Server 2008 R2. After the reboot, you can log into your server using the administrator account and password that was previously assigned to the local administrator account. NOTE: the password that you were using, is now assigned as your domain admin. It is advisable to make sure that password is STRONG.
October 5, 2011 06:48 by
Scott
In this tutorial, I will show you how to get column name and corresponding datatypes in particular table using SQL Server.
Description:
I have one table with lot columns in database at that time I tried to know the column names and corresponding datatypes and their maximum sizes in particular table for that I written the following query in SQL server to get column names and datatypes in particular table.
USE MySampleDB
GO
SELECT column_name 'Column Name',
data_type 'Data Type',
character_maximum_length 'Maximum Length'
FROM information_schema.columns
WHERE table_name = 'Country'
Demo
If anyone gets error with above query like
Invalid object name 'information_schema.columns'
This error because of case sensitive databases to rectify this error we need to write query like this
USE CRMK
GO
SELECT column_name 'Column Name',
data_type 'Data Type',
character_maximum_length 'Maximum Length'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'Country'
Here you need to enter your table name if that is in Caps lock you should enter caps lock name of your table only because it it is case sensitive.
September 27, 2011 06:38 by
Scott
September 5, 2011 11:09 by
Scott
Error message when I try to restore a database backup to SQL Server 2008
Msg 3176, Level 16, State 1, Line 1 File 'D:\SQL Server 2008 DBs\test01.mdf' is claimed by 'SCTA_ORG_SECOND'(3) and 'SCTA_ORGANIZATION'(1). The WITH MOVE clause can be used to relocate one or more files.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally
Steps to fix this issue:
select Script Action to New Query Window as the above image so you will get the following T-SQL and here we will know the reason
RESTORE DATABASE [test01] FROM DISK = N'D:\SCTA_Org2.bak' WITH FILE = 1,
MOVE N'SCTA_ORGANIZATION' TO N'D:\SQL Server 2008 DBs\test01.mdf',
MOVE N'SCTA_ORG_SECOND' TO N'D:\SQL Server 2008 DBs\test01.MDF',
MOVE N'SCTA_ORGANIZATION_log' TO N'D:\SQL Server 2008 DBs\test01_1.ldf',
NOUNLOAD, STATS = 10
GO
so you will notice there are two files of mdf with the same name so just change the name of second one to test02 or to test01.ndf ( different extension) then run the command and it's successfully restored.
so the logical answer for this error first test01.mdf is a primary data file and the second is the secondary data file but the extension and name are same so that way you have to change the name or extension of second file with any other name or extension.
Note: the extension is anything ( it can be .fad or .ndf but .ndf is best practice to determine what this file for for example .ldf for log file , .ndf for secondary data files ..).
Finally : I think the original database backup come from SQL Server 2000 and maybe this behavior allowed in SQL Server 2000 or the name is a case sensitive ( test01.mdf not like test01.MDF).
August 26, 2011 07:18 by
Scott
Introduction
Transparent Data Encryption is a new feature in SQL Server 2008. The TDE feature provides real time encryption of both data and log files. Encryption basically working in the following way; initially the data is encrypted before it’s being written to the disk and it is decrypted before it is being read from the disk. When you are using the Transparent Data Encryption feature of SQL Server 2008 the encryption is performed by the SQL Server 2008 Database Engine and the SQL Server clients will not be aware of this change. However, before implementing this feature in Production environment I would request you to validate the solution completely in the Test Environment.
To enable Transparent Data Encryption Feature of SQL Server 2008 on a database, the DBA needs to perform the below mentioned four steps as described in Books Online:-
1. Create a master key
2. Create or obtain a certificate protected by the master key
3. Create a database encryption key and protect it by the certificate
4. Set the database to use encryption
Create a Master Key
The initial step will be to identify if there is any Master Key already created in the Instance of SQL Server 2008 where you want to implement this feature. You can verify the same by executing the below mentioned TSQL code.
USE master
GO
SELECT * FROM sys.symmetric_keys WHERE name LIKE '%MS_DatabaseMasterKey%'
GO
If there are no records found, then it means there was no predefined Master Key on the SQL Server 2008 Instance. To create a Master Key, you can execute the below mentioned TSQL code.
USE master
GO
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'pass@word1'
GO
Create or obtain a certificate protected by the Master Key
Once Master Key is created then the next step will be to Create or obtain a certificate protected by the master key. This can be achieved by executing the below mentioned TSQL code.
Use master
GO
CREATE CERTIFICATE TDECertificate WITH SUBJECT = 'SQL Server TDE Certificate'
GO
/* Verify Certificate */
SELECT * FROM sys.certificates where [name] = 'TDECertificate'
GO
Next step will be to create a new database. Once the database is created you can create a database encryption key and protect it by the certificate by executing the below mentioned TSQL code.
Create a database encryption key and protect it by the certificate
Use master
GO
CREATE DATABASE TryEncryption
GO
Use TryEncryption
GO
CREATE DATABASE ENCRYPTION KEY
WITH ALGORITHM = AES_256
ENCRYPTION BY SERVER CERTIFICATE TDECertificate
GO
Once the Database Encryption Key is created successfully you need to take a backup of the Certificate and the Private Key by executing the below mentioned TSQL code.
BACKUP CERTIFICATE TDECertificate TO FILE = 'D:\TDE\TDECertificate.cert'
WITH PRIVATE KEY (
FILE = 'D:\TDE\EncryptPrivateKey.key',
ENCRYPTION BY PASSWORD = 'Certific@tePass@word')
GO
Set the database to use encryption
The final step will be to enable encryption on the user database by executing the below mentioned TSQL code
ALTER DATABASE TryEncryption SET ENCRYPTION ON
GO
Verify Database Encryption Status
You can verify the database encryption status by executing the below mentioned TSQL code.
SELECT
DB_NAME(database_id) AS DatabaseName
,Encryption_State AS EncryptionState
,key_algorithm AS Algorithm
,key_length AS KeyLength
FROM sys.dm_database_encryption_keys
GO
SELECT
NAME AS DatabaseName
,IS_ENCRYPTED AS IsEncrypted
FROM sys.databases where name ='TryEncryption'
GO
Advantages of Transparent Data Encryption
1. Physical Security of Database Files
2. When Transparent Database Encryption feature is used all the backups of the TDE enabled database are encrypted
Disadvantages of Transparent Data Encryption
1. As Encryption is CPU intensive and it is performed at I/O level, any server with higher I/O and higher CPU load should avoid using this feature
2. This feature is only available in Enterprise and Developer Editions of SQL Server 2008
3. TDE encrypted database cannot be attached or restored in other edition of SQL Server 2008
4. If the certificate is lost then the data will be unreadable. Hence you need to protect the certificate and master key along with the database backup files
5. If you are using FILESTREAM feature, then be informed that only FILESTREAM enabled database is encrypted and not the actual files which are residing on the servers file system will be encrypted
6. There won’t be much of a benefit if you planning to use Database Backup Compression feature of SQL Server 2008
7. As TempDB database is automatically encrypted once you have enabled encryption on any of the user databases. This resulted in slow query performance for non encrypted databases which may use TempDB
For more information you can check the following link
August 9, 2011 06:18 by
Scott
The programmers are getting this error message when there is high workload on the server. And servers are experiencing high memory pressure.
In this error theire are some additional symptoms also.
1. When connecting to server will get the error message as "Login Failed".
2. Will get disconnected from server.
3. CPU usage will be very high.
4. if running "select * from sysprocesses" SPIDs will have a waittype of 0x40 or 0x0040 and a last_waittype of RESOURCE_SEMAPHORE.
5. The System Monitor object SQLServer:Memory Manager displays a non-zero
value for Memory Grants Pending.
6. SQL Profiler displays the event "Execution Warnings" that includes
the "Wait For Memory" or the "Wait For Memory Timeout" text.
Reasons for this error is memory intensive queries are getting qued and are not getting resources before timout period. And after timout period and getting timout. By default query wait period is -1 by setting non-negative number you can improve the query wait time.
Other reasons for this errors are not properly optimised queries, memory allocation for sql server is too small.
Solutions for this error include the following.
1. Optimise the performance of queries using sql profiler.
2. Distrybution statistics should be uptodate.
3. Watch the system monitor trace to see the memory usage of sql server.
4. If you are running SQL Server 7.0, test disabling parallelism for SQL Server 7.0 by turning the max degree of parallelism configuration option off.
July 20, 2011 05:16 by
Scott
Razor Layout pages are the equivalent to MasterPages in ASP.NET Web Forms and the Web Forms View Engine within ASP.NET MVC. Just as it is possible to nest MasterPages, it is also possible to nest Razor Layout pages. This article explores the process required to achieve nesting of Layout pages using the Razor View Engine in MVC 3, or WebMatrix Web Pages sites.
You would consider using nested layout pages if you were building a corporate site for a global company, for instance, which is comprised on many divisions, each having their own look and feel. There may be a common look and feel for the header and footer of the site, but the navigation and content changes in both structure and appearance depending on which division of the company is being featured. The imaginary company that the sample site relates to has a number of divisions, one of which is Automation and another for Electronics. Each of them has their own branding which needs ot be catered for. For simplicity's sake the following walkthrough illustrates the use of Razor in a Web Pages site built using WebMatrix, but the principals are exactly the same if you are using ASP.NET MVC 3.
Step 1
Create a new site using the Empty Site template and name this Nested Layouts. Add two folders to the site – one called Content and the other called Shared. Add a new CSS file to Content and leave it with the default file name of StyleSheet.css. Add the following code to it:
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 80%;
padding: 0;
margin: 0;
}
h1{
color: #0093c0;
}
#wrapper{
background-color: #c1dfde;
padding: 10px;
width: 800px;
margin: auto;
min-height: 600px;
}
#electronics, #automation{
min-height: 400px;
}
#electronics{
background-color: #8ec1da;
width: 650px;
float: left;
}
#automation{
background-color: #ffe8d3;
}
#electronicsnav{
background-color: #fff;
min-height: 400px;
width: 150px;
float: left;
}
#automationnav{
background-color: #dedede;
}
#automation h3{
color: #997d63;
}
Step 2
Add a CSHTML file to the Shared folder and name it _MainLayout.cshtml. Change the existing code so that it looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>@Page.Title</title>
<link href="@Href("~/Content/StyleSheet.css")" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header"><h1>Global Enterprises</h1></div>
<div id="nav">
<a href="Home">Home</a> |
<a href="About">About</a> |
<a href="Engineering">Engineering</a> |
<a href="Electronics">Electronics</a> |
<a href="Automation">Automation</a> |
<a href="Contact">Corporate</a> |
<a href="Contact">Contact Us</a>
</div>
@RenderBody()
</div>
</body>
</html>
Step 3
Add another CSHTML file to the Shared folder and name this one _AutomationLayout.cshtml. Replace the existing code with this:
@{
Layout = "~/Shared/_MainLayout.cshtml";
}
<div id="automationnav">
<a href="Products">Products</a> |
<a href="Services">Services</a> |
<a href="Support">Support</a> |
<a href="Team">The Team</a> |
</div>
<div id="automation">
@RenderBody()
</div>
<div id="footer">The Automation Division Footer</div>
Step 4
Now add a third CSHTML file to the Shared folder. Name it _ElectronicsLayout.cshtml, delete the existing code and add the following:
@{
Layout = "~/Shared/_MainLayout.cshtml";
}
<div id="electronicsnav">
<a href="Products">Products</a> <br />
<a href="Services">Services</a> <br />
<a href="Support">Support</a> <br />
<a href="Team">The Team</a> <br />
</div>
<div id="electronics">
@RenderBody()
</div>
<div id="footer">The Electronics Division Footer</div>
Step 5
Add a CSHTML file to the root folder. Name this one Automation.cshtml and replace the existing code with this:
@{
Layout = "~/Shared/_AutomationLayout.cshtml";
Page.Title = "Automation";
}
<h3>Automation Home Page</h3>
Step 6
Finally, add another CSHTML file to the root folder and call it Electronics.cshtml. Replace the existing code with the following:
@{
Layout = "~/Shared/_ElectronicsLayout.cshtml";
Page.Title = "Electronics";
}
<h3>Electronics Home Page</h3>
Making sure that the Electronics page is selected in the left pane, click the Run button to launch the page in your browser. Notice that the second navigation has a white background and the main area has a blue background. Click the Automation link in the top navigation. See how the colours change? The main content is a brownish-pink colour as is the secondary navigation. The heading in the main content area changes colour too. Most obviously, the Electronics navigation is displayed vertically whereas the Automation navigation is horizontal.
What defines a Layout page is a call to the RenderBody method. In this exercise you created a layout page from _MainLayout.cshtml by placing @RenderBody() in the file, and by matching that with Layout declarations in both the _AutomationLayout.cshtml and ElectronicsLayout.cshtml files. You also added calls to RenderBody in both of those files, thus turning them into layout pages. Electronics.cshtml and Automation.cshtml each contained Layout declarations pointing to their own layout page, completing the content – layout relationship. There is no limit to the number of levels to which you can nest layout pages.
The design of the pages won’t win any awards, but this sample serves to illustrate that nesting layout pages can offer a very flexible solution to certain problems.
July 13, 2011 06:14 by
Scott
With CSS (Cascading Style Sheets) you can use custom fonts on your website. Normally your visitors can only see the fonts that are already installed on their computers. So if you use a font that is not installed on your website visitor’s computer then his or her browser will show some other font that is there on the computer. That’s why when you are defining a font for an element (such as <p>) you often specify multiple fonts so that if your preferred font is not available your CSS file should use the available alternatives.
Conventional way of using custom fonts for headings and logos etc. is creating the text in a graphic editor and then using the image file. From the perspective of SEO this is not appropriate; you must use text as much as possible.
Now there is a way around in CSS that lets you use custom fonts, downloadable fonts on your website. You can download the font of your preference, let’s say cool_font.ttf, and upload it to your remote server where your blog or website is hosted.
Then from within your CSS file (or wherever you are defining your styles) you have to refer to that custom font in the following manner:
@font-face {
font-family: cool_font;
src: url('cool_font.ttf');
}
After that you can use it just like a normal CSS declaration:
p.custom_font{
font-family: cool_font; /* no .ttf */
}
This way you can use as many custom fonts as you feel like on your website.
June 23, 2011 06:03 by
Scott
Visual Studio has a cool user interface for publishing a website using the Publish Web Site dialog, accessible by selecting Build, Publish Web Site. You can use this dialog to pre-compile your website and avoid having to deploy source code.
Visual Web Developer Express doesn't offer this dialog, but because the Publish Web Site dialog is just a front-end for aspnet_compiler.exe, you can use aspnet_compiler.exe from a command prompt to accomplish the same thing if you are a VWD user. While using aspnet_compiler.exe from a command prompt gives you the same functionality, using a menu option is a lot more user-friendly and avoids possibly typos that can be frustrating.
In this post, I'm going to show you how you can add some menu options to VWD that will automate the user of aspnet_compiler. It won't give you the same flexibility and convenience you get with the full-blown Visual Studio, but it will come darn close.
Note: While I will show these steps in Visual Web Developer 2005 Express Edition, you can use the same steps for Visual Web Developer 2008 Express Edition.
To add the new menu item, I'll use the External Tools option on the Tools menu in VWD. (This menu option is also available in Visual Studio.) Using the External Tools dialog, you can add menu items that will execute external applications, and you can also control command line arguments that are passed to your external application and more.
Note: I also explain how to do this in my book, The Expression Web Developer's Guide to ASP.NET 3.5.
We'll create two menu items; one for pre-compiling an updatable application and another for a non-updatable application.
1. Launch Visual Web Developer Express.
2. Select Tools, External Tools to display the External Tools dialog.
3. In the Title box, enter Pre-&Compile (non-updatable).
4. Click the browse button next to the Command box and browse to aspnet_compiler.exe located in c:\Windows\Microsoft.NET\Framework\v2.0.50727.
5. Click Open to add the command line for aspnet_compiler.exe.
Now that you've got the correct command line for the aspnet_compiler.exe, it's time to add the arguments that will correctly pre-compile your application. This is where you'll see the true power of the External Tools dialog.
1. Type -p " in the Arguments box. (That's an opening double-quote after the p.)
2. Click the right-facing arrow next to the Arguments box and select Project Directory.
3. Add a trailing double-quote to the Arguments box.
4. Press the spacebar to add a space at the end of the existing arguments.
5. Type -v / " after the space you just entered.
6. Click the right-facing arrow next to the Arguments box and select Project Directory.
7. Type \..\CompiledApp" after the existing arguments.
At this point, the Arguments box should contain the following:
-p "$(ProjectDir)" -v / "$(ProjectDir)\..\CompiledApp"
Now check the Close on Exit checkbox and click OK to add the new command to your Tools menu.
You can create another menu item that will compile the application and allow it to be updated by creating another entry using Pre-Co&mpile (updatable) as the Title and by appending -u to the arguments.
After you complete these steps, your pre-compiled application will be saved at the same level as your application's folder. For example, if your website exists in the c:\MyWebsites\WebApplication1, the pre-compiled application will be saved to c:\MyWebsites\CompiledApp. If that folder structure doesn't suit you, you can alter the steps above for your own purposes.