Dot Net Learning Zone Blog

A blog about to learn Dot Net

Entity Framework – SaveChanges() doesn’t get the generated Identity key

Posted by Rajesh on December 24, 2010

Step to get identity key
Suppose T_Emp is table placed on emp.edmx. Now open with emp.edmx in xml and find EntityType Name=”T_EMP”.
Finally , what you have to do add StoreGeneratedPattern=”Identity” in primary key . Now Save the edmx and execute the project.
Now you can get identity key after SaveChanges()

Entities e1 = new Entities();
T_Empl a = new T_Empl();
a.Name = “Rajesh”;
e1.AddToT_Empl(a);
e1.SaveChanges();
var id = a.ID;
——————————————————
<EntityType Name=”T_EMP”>
<Key>
<PropertyRef Name=”ID” />
</Key>
<Property Name=”ID” Type=”number” Nullable=”false” StoreGeneratedPattern=”Identity”/>
<Property Name=”Name” Type=”varchar2″ MaxLength=”100″ />
</EntityType>

Posted in Entity framework | Leave a Comment »

How to validate text box with only numeric value with two decimal place

Posted by Rajesh on December 24, 2010

We have created a sample project in windows form in c#. There is a text box which accept only numeric value with decimal like 1234.56.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

string strNumber = “0123456789.”;

private void textBox1_Leave(object sender, EventArgs e)
{

textBox1.Text = Convert.ToDecimal ( textBox1.Text).ToString(“N2″).Replace (“,”,”");
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (strNumber.IndexOf(e.KeyChar) == -1)
{
e.Handled = true;
}

if ((textBox1.Text.IndexOf(‘.’) > -1) && (e.KeyChar == ‘.’))
{
e.Handled = true ;
}

}
}
}

Posted in Windows Form | Leave a Comment »

How To Delay Sign an Assembly in .NET 2.0

Posted by Rajesh on May 27, 2010

How To Delay Sign an Assembly in .NET 2.0
J.D. Meier, Alex Mackman, Blaine Wastell, Prashant Bansode, Chaitanya Bijwe

[edit]
Summary of Steps
Step 1. Create a public Key File for Delay Signing
Step 2. Delay sign your assembly

[edit]
Step 1. Create a public Key File for Delay Signing
When you use delay signing, distribute your public key in a .snk file that just contains the public key. Then, use the -keyfile compiler switch while you delay–sign the assemblies, or continue to use the AssemblyKeyFile attribute if you have existing .NET 1.x code that uses this attribute.
The signing authority performs the following procedure to create a public key file that developers can use to delay sign their assemblies.
[edit]
Creating a Public Key File for Delay Signing
To create a public key file for delay signing
1. Create a key pair for your organization.sn.exe -k keypair.snk
2. Extract the public key from the key pair file. sn -p keypair.snk publickey.snk
3. Protect Keypair.snk, which contains both the private and public keys. For example, put it on a compact disc or other hardware device, such as a smart card, and physically secure it.
4. Make Publickey.snk available to all developers. For example, put it on a network share.

[edit]
Step 2. Delay Sign Your Assembly
This procedure is performed by developers.
[edit]
Delay Signing an Assembly
To delay sign an assembly
1. In Visual Studio .NET 2005, display the project properties.
2. Click the Signing tab, and select the Sign the assembly and Delay sign only check boxes.
3. In the Choose a strong name key file: drop-down box, select .
4. In the file selection dialog box, browse to the public key (.snk) and click OK.
5. Build your assembly. The complier will build a strong named assembly signed using the public key from the selected key pair (.snk) file. Note A delay signed project will not run and cannot be debugged. You can, however, use the Strong Name tool (Sn.exe) with the -Vr option to skip verification during development.
6. The delay signing process and the absence of an assembly signature means that the assembly will fail verification at load time. To work around this, use the following commands on development and test computers.
 To disable verification for a specific assembly, use the following command.
sn -Vr assembly.dll
 To disable verification for all assemblies with a particular public key, use the following command.
sn -Vr *,publickeytoken
 To extract the public key and key token (a truncated hash of the public key), use the following command.
sn -Tp assembly.dll Note Use an uppercase -T switch.
7. To fully complete the signing process and create a digital signature to make the assembly tamper proof, execute the following command. This requires the private key, and as a result the operation is normally performed as part of the formal build/release process. The following command uses key pair contained in the Keypair.snk file to re-sign an assembly called Assembly.dll with a strong name. sn -R assembly.dll keypair.snk Done

Posted in ASP.net2.0 | Leave a Comment »

Which w3wp.exe Process Belongs to Which App Pool in IIS6 

Posted by Rajesh on May 7, 2010

There is tool IISApp.vbs in windows 2003 server which list all the application,application Pool Name and PID.

The script is already placed in systemroot\system32 on Windows Server 2003 so simply go to your Command Prompt and type in iisapp.vbs (the .vbs is optional) and you’ll have an instant list of all the App Pool information you’ve always wanted to know. You may need to type cscript iisapp.vbs if CScript isn’t your default WSH script host.
Have no worries, Microsoft has given us the exact tool for the situation. IISApp.vbs lists all the applications, their PID and their App Pool name.

Let’s see an example of the output:
W3WP.exe PID: 1468 AppPoolId: AppPoolForSite1.com
W3WP.exe PID: 3056 AppPoolId: AppPoolForSite2.com
W3WP.exe PID: 1316 AppPoolId: AppPoolForSite3.com

Posted in IIS | 1 Comment »

WCF link

Posted by Rajesh on April 29, 2010

http://msdn.microsoft.com/en-us/library/aa480210.aspx

http://msdn.microsoft.com/en-us/netframework/wcf-code-samples.aspx

http://msdn.microsoft.com/en-us/library/ms750530.aspx

Posted in C#, Uncategorized, WCF | Leave a Comment »

Operation failed or Your settings do not allow you to open files saved in older file format. To change your setting, navigate to the “Security” tab in the Options dialog box while MPP file save as Excel in Microsoft Project 2003.

Posted by Rajesh on April 29, 2010

olution:
Open Microsoft project and go to options on Tools menu. Click on options and then click the Security Tab abd then click Macro setting .on options ,Legacy format ,select “Allow loading files with legacy or not default file formats.
 To do this, follow these steps:
1.Click Start, click Run, type regedit, and then click OK.
2.Click the following registry subkey:
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\MS Project\Security
3.Double-click the LegacyFiles registry entry.

Note By default, this registry entry is not created until you change the setting on theSecurity tab in the Options dialog box. Otherwise, this registry entry is not created until you manually create this DWORD value.
4.Type one of the following values, and then click OK:
0
This is the default value if the LegacyFiles registry entry does not exist. This value corresponds to the Do not load file with legacy or non default file formats in Project option in Project 2003.
1
This value corresponds to the Prompt when loading files with legacy or non default file format option in Project 2003.
2
This value corresponds to the Allow loading files with legacy or non default file formats option in Project 2003. This option is the default option in versions of Project 2003 that are earlier than Project 2003 SP3.
5.Exit Registry Editor.

Posted in Microsoft Project | Leave a Comment »

Configuration file for Gac ; Read confiuration file from GAC

Posted by Rajesh on April 25, 2010

Steps:

1) Create class library (Dal)

2) Generate strong name

3) Assign strong name with class library

4) Add config file(App.Config)

5) In App.Config File ,write

6) Compile and build class library

7) put assembly (Dal.dll) in Gac

8) go to run and Type c:\windows\assembly\gac_msil ,There is folder named as Dal will be appeared and within Dal folder there is folder naming like versionName_Publickey. Put Config file in this location c:\windows\assembly\gac_msil\Dal\ versionName_Publickey

How to read config file

public string GetConnectionString()

{

string strConfig;

String strDal = "";

string strAppPath = AppDomain.CurrentDomain.BaseDirectory;
string strAssPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

Configuration config2 = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location);

strDal = config2.AppSettings.Settings["SQLConnectionString"].Value;

if (ConfigurationManager.AppSettings["SQLConnectionString"] != null)

strConfig = ConfigurationManager.AppSettings["name"];

else

strConfig = "Unbale to read App.config File";

return strConfig;

}

Posted in C# | Leave a Comment »

How to add reference in SSIS

Posted by Rajesh on April 25, 2010

1 ) put assembly in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

OR C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies

for accessing the dll , generate strong name for assemblies and put in Gac folder C:\windows\assembly\

Open the Add Reference dialog box again and the assembly should be visibile.

Posted in Uncategorized | Leave a Comment »

Execute SQL Task Pragmatically

Posted by Rajesh on April 25, 2010


Dim p As New Package()

Dim cm As ConnectionManager = p.Connections.Add("ADO.NET")

cm.ConnectionString = " Data Source=rajeshsharma\sql2005; Integrated Security=SSPI;Initial Catalog=test;"
Dim e As Executable = p.Executables.Add("STOCK:SQLTask")
Dim th As TaskHost = CType(e, TaskHost)
Dim est As ExecuteSQLTask = CType(th.InnerObject, ExecuteSQLTask)
est.Connection = cm.Name
est.SqlStatementSourceType = SqlStatementSourceType.DirectInput
est.SqlStatementSource = " CREATE TABLE TestTable7 ( ID int NOT NULL, Description nchar(100)); "
'run the package

Dim r As DTSExecResult = p.Execute()
If (r = DTSExecResult.Success) Then

End If

Posted in SSIS, Uncategorized | Leave a Comment »

Get Windows Service installed Path

Posted by Rajesh on April 25, 2010

using System;
using System.Management;
using System.ServiceProcess;
using System.IO;

namespace ConsoleApplication1
{
class Program
{

private static string _ServiceName = “TestService”;
static void Main(string[] args)
{

ServiceController[] srvControllers = ServiceController.GetServices();

foreach (ServiceController service in srvControllers)
{

if (service.ServiceName == _ServiceName)
{
Console.WriteLine(GetServicePath(_ServiceName));
Console.ReadLine();
}
}

//GoogleUpdaterService
}
public static string GetServicePath(string serviceName)
{
string strServiceName = “”;
using (ManagementObjectSearcher mos = new ManagementObjectSearcher(“SELECT PathName FROM Win32_Service WHERE Name = \”" + serviceName + “\”"))
{
foreach (ManagementObject mo in mos.Get())
{
strServiceName = Path.GetDirectoryName(mo["PathName"].ToString());
}
}

return strServiceName;
}
}

}

Posted in C# | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.