Saturday, September 20, 2008

Configaration Manager Missing in Visual Studio

Configaration Manager is what we use to set the build mode(debug or release),some times you might not see the option either in the task bar or in the context menu of the solution.If that is the case you can get that option back by checking on

Tools --> Options --> Projects and Solutions --> Show Advanced Build Configarations.

Subversion SVN Backup - HotCopy Not a folder copy

Subversion hotcopy is tricky, because you have to empty the contents of the destination folder before you run the svnadmin hotcopy command.

To do this I create a console vb.net app and run it before the svnadmin command runs.App is really simple and has the following code in it.


Try
''share of the destination folder
Dim folder As String = "\\svnbackupserver\svnreposbackup"
Dim rootFiles() As String = System.IO.Directory.GetFiles(folder)
For Each file In rootFiles
System.IO.File.SetAttributes(file, FileAttributes.Normal)
System.IO.File.Delete(file)
Next
Dim dr() As String = System.IO.Directory.GetDirectories(folder)
For Each item In dr
Dim str() As String = System.IO.Directory.GetFiles(item)
For Each item1 In str
System.IO.File.SetAttributes(item1, FileAttributes.Normal)
Next
System.IO.Directory.Delete(item, True)
Next
Catch ex As Exception
Print(ex.Message)
End Try
End Sub
'''''''''''''''''''''

C:\Batch\SVNBackup.exe svnadmin hotcopy \\svnserver\svnrepo \\svnserverbackup\SvnReposBackup

Subversion Apache Authorization File

Once authentication is done the next step is authorization,which is used to maitain permissions by creating groups or adding individual users to the projects or folders.

#Note: Active Domain accounts require "DomainName\username"
#Note: all usernames are case sensitive and should be created/entered in lowercase

[groups]
admin = DomainName\svnadmin
managers = DomainName\manager1,DomainName\manager2
inhouse_developers = DomainName\developer1,DomainName\developer2
interns = DomainName\intern1
contracters= contracter1,contracter2,contracter3

# These are the permissions allowed for each PROJECT
# Note "/" assigns permission to the entire repository
# "/Test" assigns permission to only "/Test" project
#inhouse_developers has access to entire repository
#contractors has only access to Test Project
#admin has access to entire repository

[/]
@admin = rw
@managers = r
@inhouse_developers= rw

[/Test]
@inhouse_developers= rw
@contracters = rw

Subversion Apache - Using network shared folder for a repository

One of the nicest things Subversion has to offer along with apache is its capability of storing the repository on a netwok share.You should use the following line in the apaches httpd.conf files location block.

SVNPath "//SnvServer/SVNREPO/"

NOTICE THE SHARES HAS FORWARD SLASHES INSTEAD OF BACK SLASHES(used in a typical windows network share)

Subversion Apache Windows Authentication and Custom Authentication

Man I cannot tell how much flexibility Subversion with Apache has to offer.One thing we wanted to do is authenticate user against Active Directory if the user has a login otherwise use a encrypted file.

Here is how the configaration of the apache httpd.conf file looks like to acheive the above.

################

DAV svn
SVNPath E:\SvnRepos
AuthName "Enter username and password"

#Authorization File that has user groups and permissions
AuthzSVNAccessFile "C:\Program Files\Apache Group\Apache2\conf\svn-auth.conf"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIDomain mydomain
SSPIOfferBasic on
SSPIOmitDomain On


# Htpasswd Logins.
AuthType Basic
AuthAuthoritative Off

#passwd file that is generated from htpasswd tool
AuthUserFile "C:\Program Files\Apache Group\Apache2\conf\passwd"
require valid-user

Everything above is self explanatory and the above statements should be in the Location block.

Sunday, September 14, 2008

use XML and OPENXML to perform Data Manipulation : Table Variable as a parameter to stored procedure

There might be times where you want to perform operations on multiple rows with a single call to the database using a stored procedure.But the problem is SQL Server has no table parameter that can take a collection of rows.To solve this problem u can pass all the rows in a string variable, parse the string into columns and rows and perform the operation you want.Sometimes you might endup sending the delimeter in the data that can cause the parsing to break.A cleaner solution is to pass the xml string and use open xml to transform string data into rows.

Following function is used to build the required xml string for the strored procedure.

Private Shared Function BuildCustomerXMLString(ByVal cc As CustomerCollection) As String

Dim ms As New MemoryStreamDim sr As StreamReader

Dim XMLString As String

Dim writer As New XmlTextWriter(ms, System.Text.Encoding.Unicode)

writer.Formatting = Formatting.Indented

writer.WriteStartElement("ROOT")

For Each lcc As Customers In cc
writer.WriteStartElement("Customer")
writer.WriteAttributeString("CustomerID", XmlConvert.ToString(lcc.CustomerID))
writer.WriteAttributeString("CustomerName", lcc.CustomerName)
writer.WriteAttributeString("CustomerEmail", lcc.CustomerEmail)
writer.WriteEndElement()
End If
Next
''End for root

writer.WriteEndElement()

''commit and close the writer

writer.Flush()ms.Position = 0

''create the stream from the Memory Stream

sr = New StreamReader(ms)''Get the string from the stream

XMLString = sr.ReadToEnd()

Return XMLString

End Function

'''''''''''''''''''''''

Following strored procedure is used to update the customer information using the openxml.


CREATE PROCEDURE [dbo].[uspUpdateCustomerInfo]
(
@CustomerInfo varchar(max)
)
AS
SET NOCOUNT ON;
DECLARE @idoc int;
BEGIN TRY
DECLARE @InputTable table (
CustomerID uniqueidentifier
,CustomerName varchar(50)
,CustomerEmail varchar(50)
);
-- CREATE A HANDLE (iDoc) FOR THE XML DOCUMENT
-- BECAUSE THE OPENXML() STATEMENT NEEDS IT.
--
EXEC sp_xml_preparedocument @idoc OUTPUT, @CustomerInfo;
INSERT @InputTable (
CustomerID
,CustomerName
,CustomerEmail
)
SELECT
CustomerID
,CustomerName
,CustomerEmail
FROM OPENXML (@idoc, '/ROOT/Customer',1)
WITH (
CustomerID uniqueidentifier
,CustomerName varchar(50)
,CustomerEmail varchar(50)
) c;

UPDATE c
SET
CustomerID = it.CustomerID
,CustomerName = it.CustomerName
,CustomerEmail = it.CustomerEmail
FROM Customers c
INNER JOIN @InputTable it ON it.CustomerID = c.CustomerID;
GO