Monday, December 10, 2007
ServiceController class to interact with windows service
Friday, December 7, 2007
Thursday, December 6, 2007
Opening a File e.g. PDF, EXCEL, WORDD etc.
Process pr = new Process();
pr.StartInfo = ps;
pr.Start();
Wednesday, December 5, 2007
TraceListeners
using System.Diagnostics;
Stream str = File.Create(@"c:\test_env\log.txt");
TextWriterTraceListener twl = new TextWriterTraceListener(str);
ConsoleTraceListener cwl = new ConsoleTraceListener();
EventSourceCreationData esct = new EventSourceCreationData("", ""); ;
esct.MachineName = ".";
esct.LogName = "Application";
esct.Source = "MyLog";
if (!EventLog.SourceExists("MyLog"))
{
EventLog.CreateEventSource(esct);
}
EventLogTraceListener elt = new EventLogTraceListener("MyLog");
Trace.Listeners.Add(twl);
Trace.Listeners.Add(cwl);
Trace.Listeners.Add(elt);
Debug.WriteLine("Hello Debug");
Trace.WriteLine("Hello Trace");
Trace.Flush();
Monday, December 3, 2007
Code Access Security (CAS) Policy - Tool Caspol.exe
Friday, November 30, 2007
SECUTIL to retrieve public key from assembly.
secutil -hex -c -s xyz.dll > key.txt
Public Key =
0x00240000048000009400000006020000002400005253413100040000010001
00E373389B3552EFC472D90F0CBE7F55D81FAA9CB7CF9C9332164A3B11B208DCA
2D9D872E610663684D0B664BC222B5B426C6791B09FAC13A1BD52F11AF63421A9
E1721C134904AC2253C6F84A6EB1293770A7AED247DC2D119DE09DF29E4BCAF76
BC941CEAA8528280541A360C7B8D98238E24CFC101C2B90D5CBFE95A35DD7C2
Name =
STNameLib
Version =
1.0.0.0
Success
User friendly name of the owner of the file.
using System.Security.Principal;
using System.Security.AccessControl;
FileSecurity fs = File.GetAccessControl(@"C:\CERT\Thinking_in_C_\Thinking in C#.pdf");
NTAccount ntac = fs.GetOwner(typeof(NTAccount)) as NTAccount;
Console.WriteLine(ntac.Value);
Tools for Interoperability between the.NET Framework and COM
- For calling COM APIs from managed code, use Type Library Importer (Tlbimp.exe) which takes a type library as input and outputs a .NET Framework assembly and associated managed metadata.
- For calling managed code from COM, use Type Library Exporter (Tlbexp.exe), which takes a managed assembly as input, and generates a type library containing COM definitions of all the public types defined in that assembly.
- For calling managed components from COM clients, use Assembly Registration Tool (Regasm.exe), which reads the metadata within a .NET Framework assembly, and adds the registry entries so that COM clients can create managed classes.
- For calling ActiveX controls, use Windows Forms ActiveX Control Importer (Aximp.exe), which takes an ActiveX control’s type library as input and generates a wrapper control that allows the control to be hosted in Windows Forms.
Windows Forms ActiveX Control Importer (Aximp.exe)
The ActiveX Control Importer converts type definitions in a COM type library for an ActiveX control into a Windows Forms control.
Windows Forms can only host Windows Forms controls — that is, classes that are derived from Control. Aximp.exe generates a wrapper class for an ActiveX control that can be hosted on a Windows Form. This allows you to use the same design-time support and programming methodology applicable to other Windows Forms controls.
To host the ActiveX control, you must generate a wrapper control that derives from AxHost. This wrapper control contains an instance of the underlying ActiveX control. It knows how to communicate with the ActiveX control, but it appears as a Windows Forms control. This generated control hosts the ActiveX control and exposes its properties, methods, and events as those of the generated control.
Assembly Registration Tool (Regasm.exe)
The Assembly Registration tool reads the metadata within an assembly and adds the necessary entries to the registry, which allows COM clients to create .NET Framework classes transparently. Once a class is registered, any COM client can use it as though the class were a COM class. The class is registered only once, when the assembly is installed. Instances of classes within the assembly cannot be created from COM until they are actually registered. --
http://msdn2.microsoft.com/en-us/library/tzat5yw6(VS.71).aspx
Monday, November 19, 2007
Friday, November 16, 2007
CultureInfo & RegionInfo
CultureInfo cu = new CultureInfo("hi-IN");
Console.WriteLine("Display Name: {0}",cu.DisplayName);
Console.WriteLine("English Name: {0}",cu.EnglishName);
Console.WriteLine("LCID: {0}", cu.LCID);
Console.WriteLine("Calendar: {0}", cu.Calendar);
Console.WriteLine(Environment.NewLine);
Console.WriteLine("---------Properties of System.Globalization.RegionInfo Class-----------------");
RegionInfo re = new RegionInfo("IN");
Console.WriteLine("Currency English Name: {0}",re.CurrencyEnglishName);
Console.WriteLine("Metric System: {0}",re.IsMetric);
To use Custom Culture or Region use CustomCultureAndRegionInfoBuilder class, for this Add reference to the Dll sysglobal.dll.
Send mail using dot net
using System.Net.Mail;
SmtpClient sp = new SmtpClient("smtp.gmail.com", 587);
//sp.Credentials = CredentialCache.DefaultNetworkCredentials;
sp.EnableSsl = true;
sp.Credentials = new NetworkCredential("madhusudan.gohil", "*************");
MailMessage m = new MailMessage("madhusudan.gohil@gmail.com", "ms_gohil@yahoo.com");
m.Attachments.Add(new Attachment(@"c:\amita.jpg"));
m.Subject = "test attach";
try
{
sp.Send(m);
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
Sunday, November 4, 2007
Security Tip
I.e. if some malicious user passes a drop table statement to the input it won't get executed.
Saturday, November 3, 2007
ManagementObjectSearcher
using System.Management;
ManagementObjectSearcher searchService =
new ManagementObjectSearcher("Select * from Win32_Service where state='stopped'");
foreach (ManagementObject svc in searchService.Get())
{
Console.WriteLine(svc["Name"]);
}
ManagementObjectSearcher searchDisk =
new ManagementObjectSearcher("Select * from Win32_Share");
foreach (ManagementObject svc in searchDisk.Get())
{
Console.WriteLine(svc["Name"]);
}
Friday, November 2, 2007
Dot Net Questions
A) Assembly is a primary building block of a .NET Framework application. It is a collection of resources, type definition and implementation of these types in a single unit. The assembly comprises of three entities i.e. IL, Manifest and Metadata. Assemblies are self describing by means of their manifest which is an integral part of assembly.
Q) What is assembly manifest?
A) An assembly manifest is a collection of data (also called metadata of assembly) that contains all the metadata needed to specify the assembly's version requirements and security identity, and all metadata needed to define the scope of the assembly and resolve references to resources and classes.
Q) Information stored in assembly manifest?
A) Assembly name, Version number, Culture, Strong name information (if given), List of all files in assembly, Type reference information, Information of referenced assemblies,
Q) Main function of Assembly manifest?
A) Renders the assembly self describing, enumberates the other assembly on which this assembly depends.
Q) Where are shared Assemblies stored?
A) GAC
Q) Where is global assembly cache located on system.
A) c:\winnt\assembly
Q) What are the ways to deploy an assembly in the GAC?
A) Installer, drag drop to GAC location, use GacUtil.exe a command line tool.
Links for questions and answers
http://aspnet2008.blogspot.com/
Wednesday, October 31, 2007
Trust Level in Dot Net
"system.web"
"securitypolicy"
"trust level="medium""
"/trust"
"/securitypolicy"
Application operating under a Medium trust level have no registry access, no access to windows eventlog, and cannot use reflection, file system access is limited to the applications virtual directory hierarchy.
Different trust levels
"trust level="Full|High|Medium|Low|Minimal""
ASP.Net 1.1 and 2.0, medium trust application can access SQL server database because SQL Server data provider does not demand full trust and SqlClientPermission is granted to medium trust applications.
In 2.o Oracle .net provider, the OLE DB .NET data provider, ODBC .NET data provider no longer demand full trust.
DOT NET 2.0 Notes Part 3
Thread th = new Thread(new ThreadStart(Test));
ThreadStart is a delegate which doesn't take parameter, we can give a reference to the method which do not take any parameter.
Thread.Sleep(3000); //will cause the current thread to sleep for 3 secs, i.e. 3000 ms.
th.Join(); //if any other thread has no finished its task it will block the main thread till the another thread finishes
ThreadPriority Enumeration consists of values that can be use to set or get the thread priority.
ThreadPriority.Highest, ThreadPriority.Lowest, ThreadPriority.Normal etc.
To pass information to the thread use delegate ParameterizedThreadStart
E.g.
//function to be called by the ParameterizedThreadStart
public static void TestParametereized(int i)
{
}
ParameterizedThreadStart pt = new ParameterizedThreadStart(TestParametereized);
Thread thP = new Thread(pt);
thP.Start(10);
// to stop the thread, system prepares ThreadAbortException, whether caught
// or not thread will be stopped.
thP.Abort();
Code between Thread.BeginCriticalRegion(); and Thread.EndCriticalRegion(); is treated as a single line of code, while executing the code between this block if the thread receives a Abort Signal it will complete executing the code between this block and then die throwing ThreadAbortException, this way it will leave the object in a consistent state.
Q) What type of object is required when starting a thread that requires a single parameter?
A) ThreadStart delegate.
Q) What method stops a running thread?
A) Thread.Abort
Sharing Data Multi Threading
Synchronization with windows kernel objects:
Mutex : Allows synchronization (locking mechanism) across AppDomain and Process boundries, e.g. Single instance application.
Semaphore
Event : Provides a way to notify to multiple threads that event has occured.
Mutex, Semaphore, AutoResetEvent, ManualResetEvent all derive from WaitHandle class.
On mutex created with a well-known name, one can use OpenExisting method to get a Mutex that has already been created.
Event class are type of kernel objects that has two states, on and off. These states allow threads across an application to wait until an event is signaled to do something specific.
Asynchronous Programming Model
Three styles to deal with handling of the end of the call in an asynchronous call.
Wait until done
Polling
Callback
Wait until done: Use BeginInvoke methode and pass null for callback and stateobject. E.g. BeginRead of FileStream, call EndInvoke (e.g. EndRead) this will block the thread until the asynchronous call is done.
E.g.
IAsyncResult iResult = fw.BeginRead(buffer,0,buffer.Length,null,null);
int nByteRead = fw.EndRead(iResult); //thread will be blocked, until the asynch is done.
Polling: Use BeginRead and get the reference to AsynchResult, Code will poll IAsyncResult to see whether it is completed.
E.g.
IAsyncResult iResult = fw.BeginRead(buffer,0,buffer.Length,null,null,);
while(!iResult.IsCompleted)
{
Thread.Sleep(1000);
}
Callback Model:
System.Globalization to address the geogrophical scope of the application
Invariant Culture: This culture category is culture-insenistive, useful when creating trial application, not based on English language but is associated with it and bears more similiarity with it.
Neutral Culture: English, French, and Spanish are all neutral culture, a neutral culture is associated with Language but has no relationship to countries or region. A neutral culture is designated by the first two characters in CultureInfo class.
Specific Culture: Most Precise of three, represented by a neutral culture, a hyphen and then a specific culture abbrevation. e.g. fr-FR, en-US.
E.g. to set a culture of current thread.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
Console.WriteLine((1000).ToString("C"));
Dot Net 2.0 Notes Part 2
Q) What is serialization?
A) Serialization as implemented in the System.Runtime.Serialization is the process of Serializing and Deserializing objects so that they can stored or transferred and then later recreated.
Q) What is Serializing?
A) Seraializing is a process of converting object into a linear sequence of bytes that can be stored on disk or transferred over network.
Q) What is Deserializing?
A) Deserializing is a process of converting previously serialized sequence of bytes into an object.
E.g. Serializing
FileStream fs = new FileStream(@"c:\test_env\serialized.dat", FileMode.Create, FileAccess.Write);
//binary formatter to perform serialization
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, "This data string will be written to the file as binary data");
fs.Close();
E.g. Deserializing
FileStream fr = new FileStream(@"c:\test_env\serialized.dat", FileMode.Open);
string strIn = string.Empty;
strIn = bf.Deserialize(fr) as string;
Q) How to create a class that can be serialized?
A) If you are satisfied with the default handling of serialization then [Serializable] Attribute to the class is enough, when a class is serialized, runtime serializes all the members including private members.
refer the below example for using various attributes with serialization.
Runtime calls GetObjectData during serialization and serialization constructor during deserialization
[Serializable] //Attribute for serializing and deserializing objects of custom class
class Test:IDeserializationCallback //implement OnDeserialization which will be called once serialization is complete
{
public int i;
public int j;
//total will not be serialized and deserialized, i.e. disable serialization of specific members only.
[NonSerialized] public int total;
//if changes are made to this class, but there are serialized object of
//the instance before this field was added, OptionalField attribute would
//not affect serialization, but during deserialization if the member was not serialized
//it will leave the members value as null rather than throwing exception
[OptionalField] public int offset;
void IDeserializationCallback.OnDeserialization(object sender)
{
total = i + j;
}
}
Two methods for formatting serialized data both of which implement IRemotingFormatter interface.
For BinaryFormatter : Only for .Net Framework
using System.Runtime.Serialization.Formatters.Binary;
For SoapFormatter add reference to "System.Runtime.Serialization.Formatters.Soap" Serialize objects that will be transmitted across network.
using System.Runtime.Serialization.Formatters.Soap;
Consumes 3 to 4 times more space.
XML Serialization:
Can serialize only public data, cannot serialize private data
Cannot serialize graphs, only objects.
E.g.
TestXMLS tm = new TestXMLS(10, 20);
XmlSerializer xm = new XmlSerializer(typeof(TestXMLS));
FileStream fs = File.Create(@"c:\test_env\test.xml");
xm.Serialize(fs, tm);
Thursday, October 25, 2007
DOT NET 2.0 Notes Part 1
A) Reference type store the address of their data, also known as pointer on the stack, actual data is stored on the Heap.
Q) What are partial Classes?
A) Partial classes allows you to split a class definition accross multiple source files.
Q) Why to use Generics?
A) Casting causes boxing & unboxing which steals processor time and slows performance. Also compiler cannot detect type errors when you cast to and from Object class, instead will throw an runtime exception.
Q)What is an Interface?
A)Interface also known as contract, define common set of members that all classes that implement must provide.
Q) What is an Event?
A) An event is a message sent by an object to signal the occurance of an action.The one that raises the event is called Event Sender and the one that receives is called Event receiver.
Q) What is a Delegate?
A) A delegate is a class that holds reference to a method. A delegate class has a signature and it can hold reference to those method that matches with its signature. It is similar to typesafe pointer or callback.A delegate declaration is sufficient to declare a delegate class.
E.g.
public delegate void ButtonClicked(object sender, EventArgs args);
Note: TryParse, TryParseExact and TryCast are new to NET 2.0 previously you had to attemp parsing or conversion and catch the exception.
Conversion in Custom Type:
Implement System.IConvertible to enable conversion through System.Convert.
FileSystemWatcher Class:
FileSystemWatcher fsw = new FileSystemWatcher(@"c:\test_env");
fsw.NotifyFilter = NotifyFilters.LastWrite;
//WaitForChanged is a Synchronous method for watching a directory
//for changes and for returning a structure that contains all changes.
WaitForChangedResult wcr = fsw.WaitForChanged(WatcherChangeTypes.All);
Console.WriteLine(wcr.Name);
There are events like Created, Changed, Renamed, and Deleted.
File can be opened for writing using following.
File.Open(@"c:\test.txt", FileMode.Create, FileAccess.Write);
Stream class is the abstract base class from which all other stream classes derive from.
FileStream, MemoryStream, CryptoStream, NetworkStream, GZipStream
Different ways to open file for reading or writing using stream classes.
StreamReader sr = File.OpenText(@"c:\test.txt");
StreamWriter sw = File.AppendText(@"c:\test.txt");
FileStream fw = File.OpenWrite(@"c:\test.txt");
FileStream fr = File.OpenRead(@"c:\test.txt");
//reads a stream as a string and not series of bytes.
StreamReader srFile = new StreamReader(@"c:\test.txt");
StreamWriter swFile = new StreamWriter(@"c:\test.txt");
StreamReader is derived from Abstract class TextReader and StreamWriter is derived from Abstract class TextWriter.
StringReader and StringWriter class reads or writes to inmemory strings.
BinaryReader and BinaryWriter:
Creating a binary file:
byte[] bt = new byte[]{95,96,97,98,99};
FileStream fbinw = File.Create(@"c:\temp\test.bin");
fbinw.Write(bt, 0, bt.Length);
fbinw.Flush();
fbinw.Close();
//using binarywriter
BinaryWriter brw = new BinaryWriter(fbinw);
brw.Write(bt);
MemoryStream:
Use StreamReader to read from MemoryStream and StreamWriter to write to MemoryStream.
ArrayList:
Add, AddRange, Insert, InsertRange Methods. Indexers to set item at specific position by overwriting the object at that position.
Remove, RemoveAt, RemoveRange
Clear to empty the collection
Supports IEnumerable interface, which allows to use foreach construct.
Implements interface ICollection derived from IEnumberable and IList derivied from ICollection.
Sequential Lists: Queue and Stack
Queue : FIFO
Stack : LIFO
Dictionary:
Map key to a Value, create a lookup tables.
To iterate using foreach you should cast the object to DictionaryEntry i.e. foreach(DictionaryEntry de in hstLookup).
All dictionary class Supports IDictionary Interface.
IDictionary Interface doesn't allow the access to item by index like IList, but only allows the access by key.
IDictionary Interface has Contains, ContainsKey and ContainsValue
Hashtable
SortedList: To create a list of items that can be sorted by key.
Hashtable is very efficient but has an overhead which for fewer than 10 items can impede performance, very useful for large collection.
ListDictionary: Implemented as simple array of items under the hood, useful for small collection.
HybridDictionary: If you do not know the size, internally it changes the listdictionary to hashtable as the list grows.
OrderdDictionary
BitArray:
No add or remove method, constructor takes the size and initializes all the items with false.
Xor Method of bitarray takes another bitarray object and result is another bitarray which is Xor of two bitarray.
StringCollection is Like an ArrayList except that it accepts only string, passing anything else with cause compilation error.
StringDictionary is like hashtable except that both key and value must be string.
using System.Collections.Specialized;
Hashtable ht = CollectionsUtil.CreateCaseInsensitiveHashtable();
ht.Add("a", "Apple");
ht["A"] = "APPLE";
Console.WriteLine("Count:{0}", ht.Count); // returns one
NameValueCollection appears like a StringDictionary class, but the Add method behaves differently.
The behaviour of Add and indexer is different, indexer will overwrite the previous value if the key supplied is same.
NameValueCollection nv = new NameValueCollection();
nv.Add("A", "apple");
nv.Add("A", "america");
foreach (string st in nv.GetValues("A"))
{
Console.WriteLine("Value for A : {0}", st);
}
Value for A : apple
Value for A : america
Questions:
Q) What type of collections can be made from CollectionsUtil class?
A) Case insensitive Hashtable and Case insensitive SortedList.
Q) What type of values can be stored in StringDictionary?
A) Strings.
Wednesday, October 24, 2007
undocumented stored procedure for SQL Server
sp_MStablespace 'xyztable' //with table name.
size returned in MB
Tuesday, October 23, 2007
Screen scraping OR HTML scraping
http://en.wikipedia.org/wiki/Screen_scraping
Monday, October 22, 2007
Microsoft Acropolis
http://windowsclient.net/
http://windowsclient.net/Acropolis/
Thursday, October 18, 2007
IIS 7
The Windows Communication Foundation (WCF) programming model is one such technology that can enable communication over the standard protocols of Transmission Control Protocol (TCP), Microsoft Message Queuing (MSMQ), and Named Pipes. This lets applications that use communication protocols take advantage of IIS features, such as process recycling, rapid fail protection, and configuration that were previously only available to HTTP-based applications.
IIS 7.0 supports HTTP and HTTPS by default, but you can use additional protocols.
ApplicationHost.config file (located at %windir%\system32\inetsrv\config \) after installing IIS on Windows Server codename "Longhorn."
New Things in VS2008
- Split View Support (the ability to have both HTML Source and design open simultaneously)
- Extremely rich CSS support (CSS property window, CSS inheritance viewer, CSS preview, and CSS manager)
- Dramatically improved view switching performance (moving from source->html design mode is now nearly instantaneous)
- Support for control designers within source view (property builders, event wire-up and wizards now work in source view)
- Richer ruler and layout support (better yet, values can be automatically stored in external CSS files)
- Designer support for nested master pages
Friday, October 12, 2007
dot net 3.0 CLR
.NET 3.0 = .NET 2.0 + Windows Communication Foundation + Windows Presentation Foundation + Window CardSpace + Workflow Foundation
Thursday, October 11, 2007
RSA Alogrithm!!!
Tuesday, May 1, 2007
sql server temp table types
Tuesday, April 17, 2007
Sqlserver inbuilt stored procedure
Friday, April 13, 2007
Dynamic code invocation.
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.Reflection;
using System.Configuration;
namespace ReuseCode
{
public abstract class RunTimeMethodInvoker
{
public static object CompliedObject(string strClassCode)
{
ICodeCompiler loCompiler = CodeDomProvider.CreateProvider("csharp").CreateCompiler();
CompilerParameters loParameters = new CompilerParameters();
//this is the path where the complier will look for the referenced libaray
//loParameters.CompilerOptions = "/debug /lib:" + ConfigurationManager.AppSettings["InstallationPath"];
loParameters.ReferencedAssemblies.Add("System.dll");
// *** Load the resulting assembly into memory
loParameters.GenerateInMemory = true;
// *** Now compile the whole thing
CompilerResults loCompiled = loCompiler.CompileAssemblyFromSource(loParameters, strClassCode);
if (loCompiled.Errors.HasErrors)
{
string lcErrorMsg = "";
// *** Create Error String
lcErrorMsg = loCompiled.Errors.Count.ToString() + " Errors:";
for (int x = 0; x < loCompiled.Errors.Count; x++)
lcErrorMsg = lcErrorMsg + "\r\nLine: " + loCompiled.Errors[x].Line.ToString() + " - " +
loCompiled.Errors[x].ErrorText;
return null;
}
Assembly loAssembly = loCompiled.CompiledAssembly;
//object loObject = loAssembly.CreateInstance("Delphi.PassPods.SeatParser.CDynamicSeatDataFieldFormatter");
object loObject = loAssembly.CreateInstance("TestClass");
return loObject;
}
public static object RuntimeMethodCall(object loObject, string strFunctionName,
object[] loCodeParms)
{
object loResult = null;
loResult = loObject.GetType().InvokeMember(strFunctionName,
BindingFlags.InvokeMethod, null, loObject, loCodeParms);
return loResult;
}
}
class Program
{
static void Main(string[] args)
{
TestDynamicCode();
}
static void TestDynamicCode()
{
string strTest = "using System; using System.IO; public class TestClass { public string outputResult() { return \"hello from test\"; }}";
// *** Retrieve an object reference - since this object is 'dynamic' we can't explicitly
// *** type it so it's of type Object
object loObject = RunTimeMethodInvoker.CompliedObject(strTest);
object loResult = RunTimeMethodInvoker.RuntimeMethodCall(loObject, "outputResult", null);
Console.WriteLine(loResult.ToString());
}
}
}
Thursday, April 12, 2007
Windows PowerShell
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
Tuesday, April 10, 2007
CASE STATEMENT IN SQL SERVER
case
when charindex('M',bladder_barcode,3) > 3 and charindex('M',bladder_barcode,3) < (len(bladder_barcode)-8) then 3 else 4 end
Monday, April 9, 2007
Saturday, March 31, 2007
Saving large text to database field.
- System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
- MemoryStream mr = new MemoryStream();
bf.Serialize(mr, strCode); - byte[] bt = mr.GetBuffer();
assign this bt to the param.Value to be passed to the sqlhelper.
Retrieving a large text stored as binary in the database.
- System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf_1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
MemoryStream mr_1 = new MemoryStream(objClassCode as Byte[]);
//retrieve the code from the database and assign to the variable.
string strText = bf_1.Deserialize(mr_1).ToString();
mr_1.Close();
Friday, March 30, 2007
string.Join
Wednesday, March 28, 2007
Wednesday, March 21, 2007
Replace special characters in the file name
string strPattern = @"#/\?*#";
Regex rg = new Regex(strPattern);
if (rg.IsMatch(strTest))
{
//replaces invalid chars with __
_fileNameWithSpecialCharsReplaced = rg.Replace(value, "__");
}
Replace spaces with underscore in a string
Regex reg = new Regex(@"\s");
string strTest = "hello how are you";
string strout = reg.Replace(strTest, "_");
Friday, March 16, 2007
DTS IMPORT / EXPORT GIVES ERROR
Run the svrnetcn.exe on which MSDE is installed, SQL Server Network Utility Dialogbox will be displayed,Make sure that TCP/IP is enabled and the port is 1433.
Tuesday, March 13, 2007
MSDE Limitations
MSDE does not support SQL Mail
As of July 2004, these are the planned limitations of the next generation of MSDE, now known as SQL Server Express (which will still be a free product):
1 GB memory (for buffer, not total);
1 CPU;
50 named instances per machine;
4 GB per database (not including log files);
Monday, March 12, 2007
sql server utility to do bulk copy / insert
(see the bcp command help by typing bcp on command promp)
bcp seat_data_core out c:\core.txt -S DLG6BVV81 -U PodsUser -P pods -k -c -E -q
bcp seat_data_stage_2 out c:\stage2.txt -S DLG6BVV81 -U PodsUser -P pods -k -c -E -q
bcp seat_extra_data out c:\extra.txt -S DLG6BVV81 -U PodsUser -P pods -k -c -E -q
bcp seat_data_stage_2 in c:\stage2.txt -S usmitry-db09 -U PodsUser -P pods -k -c -E -q
bcp seat_extra_data in c:\extra.txt -S usmitry-db09 -U PodsUser -P pods -k -c -E -q
