Use sections in the config file and access them…

(NameValueCollection)ConfigurationManager.GetSection("applicationSettings/ConnectionStrings");

for the following XML fragment in the config file:-
 
<applicationSettings>
<ConnectionStrings>
<add key="DevConnectionstring" value="server=myserver1;database=mydatabase;uid=ashish;pwd=password"/>
<add key="QAConnectionstring" value="server=myserver2;database=mydatabase;uid=ashish;pwd=password"/>
<add key="ProdConnectionstring" value="server=myserver3;database=mydatabase;uid=ashish;pwd=password"/>
</ConnectionStrings>
</applicationSettings>

Visual studio 2005 Build error :- The volume for a file has been externally altered so that the opened file is no longer valid

Just clean the solution and rebuild.
 
Just dont have any idea why the above error happened this morning when I tried to add some code to a windows service and tried to build the solution.But it has a simple resolution,just clean the solution. 🙂  [Solution Explorer > Right click on the Solution> Select "Clean Solution"].
 
 
 

Convert string to byte array and viceversa

                   byte[] elementByteContent= contentObject.Content; //  this  byte array content
                    string elementStringContent = System.Text.Encoding.UTF8.GetString(elementByteContent);
                    elementStringContent = elementStringContent.Replace(" ", "");
                    if (elementStringContent == string.Empty)
                    {
                        elementStringContent = "<P>&nbsp;</P>";
                        contentObject.Content = System.Text.Encoding.UTF8.GetBytes(elementStringContent);
                    }

Removing comments using XPathNavigator.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);

 

#region Remove XML comments
System.Xml.XPath.
XPathNavigator path = xmlDoc.SelectSingleNode("w:document",xmlNSMgr).CreateNavigator();
System.Xml.XPath.
XPathNodeIterator commentsIterator = path.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);
if (commentsIterator.Count > 0)
{
while (commentsIterator.MoveNext())
{commentsIterator.Current.DeleteSelf();}}
#endregion

 

For the following XML:-(We needed to remove "<!–  Generated by Aspose.Words for .NET 4.4.1.0   –> ")

 

  <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
– <w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
– <!–  Generated by Aspose.Words for .NET 4.4.1.0
  –>
– <w:body>
– <w:p>
– <w:r>
– <w:rPr>
  <w:b />
  <w:color w:val="FF0000" />
  <w:sz w:val="24" />
  </w:rPr>
  <w:t>Evaluation Only. Created with Aspose.Words. Copyright 2003-2007 Aspose Pty Ltd.</w:t>
  </w:r>
  </w:p>
  </w:body>
  </w:document>

Process.Start() – Open the file from the application after writing on the file

There are instances where you write to a file (say XML/Text file/word) fo debugging/testing etc.In those scenarios,your program finishes writing to the file and then you open the file manually in the application(IE/Notepad/Microsoft word) to see what the program has written in that file.You can actually launch that application after you finish writing to that file from with in the program making the whole process quick.The file opens in its default application right after you finish debugging without you needing to manually open it.
 

The steps:- (2 lines):-
 
a) Include the namespace:-
using System.Diagnostics;

b) Start the process for the saved file:-
//
//Code to save the file
//
 
// Following line would open the saved file in its default application
Process.Start("SavedFullFilePath");
 
 
Example:-
// Code to save the file
XmlDocument Xdoc = new XmlDocument();
string folderPath = @"C:\Ashish\";
string upload = folderPath + "2007.docx";
string savename = folderPath + "WordPackage.xml";
ZipPackage zipPackage = null;
byte[] packageData = null;
Stream stream;
packageData = GetBytesFromFile(upload);
stream =
new MemoryStream(packageData);
if (stream != null)
zipPackage = GetZipPackageFromStream(stream);
Xdoc = RRD.DSA.SCP.OfficeAssembler.
WordToXyXmlAssembler.ConvertToXyXml(zipPackage);
Xdoc.Save(savename);

// Following line would open the saved file in its default application (Internet explorer)
Process
.Start(strSave);

 
 

can not drop user from database

Problem :-
 
I can not delete user from a database in sql2005 beta 3.
the message errror is :

TITLE: SQL Server Management Studio
—————————————-

Drop failed for User ‘Amministratore’.  (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft SQL Server&ProdVer=9.00.0981.00&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Drop+User&LinkId=20476

—————————————-
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

—————————————-

The database principal owns a schema and cannot be dropped. (Microsoft SQL Server, Error: 15138)

 

 

 

Solution:-

1) Expand Schemas(should be like a folder under <yourdatabase> -> Security) .
2) Script the the unwanted "userSchema" save it and and then Delete the schema.
3) Then, go back to the User,script the user and then delete the user.

4) Associate the schema back to the user by running the script.

Searching with different criteria in SQL server 2000

From the code calling the SP,set the parameter(s) to null if there is no value.
Have SP parameters set to null and then use COALESCE for the parameters
with the "where" clause  between the criteria as given below.
 
 
CREATE PROCEDURE SearchCustomers
@Cus_Name varchar(30) = NULL,
@Cus_City varchar(30) = NULL,
@Cus_Country varchar(30) =NULL
AS
SELECT Cus_Name,
       Cus_City,
       Cus_Country
FROM Customers
WHERE Cus_Name = COALESCE(@Cus_Name,Cus_Name) AND
      Cus_City = COALESCE(@Cus_City,Cus_City) AND
      Cus_Country = COALESCE(@Cus_Country,Cus_Country)