Monday, 5 February 2007
Some nice links
http://www.experts-exchange.com/Operating_Systems/WinXP/Q_20832633.html
Friday, 2 February 2007
Free DotNET books.
http://www.programmerworld.net/dotnet/books.htm;
Important thing while connecting to SQL server 2005 is that
u have to append serverName\SQLExpress with the server name.
Wednesday, 10 January 2007
Publishing WCF service
IIS was installed after .NET 2.0. Hence extesnions were not registered. I did it using
aspnet_regiis -i;
Hosting WCF service in IIS requires SVC extensions to be registered. I did it.
Then the most important file, Service.SVC should contain the following line.
ServiceHost Language="C#" Debug="true" Service="DerivativesCalculator.DerivativesCalculatorServiceType"
This made SVC running on IIS.
Here are soem links that helped me a lot.
Windows Communication Foundation (Indigo) Hello World Tutorial
http://dotnet.org.za/hiltong/pages/Windows-Communication-Foundation-_2800_Indigo_2900_-Hello-World-Tutorial.aspx
Metaacl.exe modifying metabase permissions for the IIS Admin Objects
http://support.microsoft.com/?kbid=267904
IIS Hosted Service Fails
http://msdn2.microsoft.com/en-us/library/ms752252.aspx
IIS Hosting Using Inline Code
http://msdn2.microsoft.com/en-us/library/ms751457.aspx
How to: Host a WCF Service in IIS
http://msdn2.microsoft.com/en-us/library/ms733766.aspx
The HTTPS protocol uses the Secure Socket Layer/Transport Layer Security (SSL/TLS) protocol. Instructions for configuring the SSL/TLS protocol on IIS are available at http://www.microsoft.com/smallbusiness/support/articles/sec_IIS_6_0.mspx#EDAA.
While enabling HTTPS for WCF service, I was facing trust relationship problem. Following code solved it. The code is available at :
http://weblogs.asp.net/jan/archive/2003/12/04/41154.aspx
Consuming Webservices over HTTPS (SSL)
When Webservices are used, a common concern is security: SOAP messages are transferred in plain text over the network, so anyone with a sniffer could intercept the SOAP message and read it. In my opinion this could happen also to binary data, but probably it requires a little bit more hacker skills. So a solution is to use HTTPS (SSL) instead of HTTP, so the communication is encrypted. To accomplish this, you need to get and install a certificate (issued by a Certificate Authority) on your webserver. In a production environment you would buy a certificate from Verisign or another well known CA, or you would install your own CA, which is a component of Windows Server. If you only want to play with HTTPS, SSL and certificates or your project is in the development phase, you can also generate a test certificate using the MakeCert.exe tool (included in the .NET Framework SDK). After that you have to add this certificate to a website in IIS, and set a port which HTTPS should use.
When you browse to a HTTPS site, you probably get a dialog window asking you if you want to trust the certificate provided by the webserver. So the responsibility of accepting the certificate is handled by the user. Let's get back to the webservice scenario, if you want to invoke a webservice located on a webserver which uses SSL and HTTPS there is a problem. When you make the call from code, there is no dialog window popping up, and asking if you trust the certificate (luckily because this would be pretty ugly in server-side scenarios); probably you'll get following exception:An unhandled exception of type 'System.Net.WebException' occurred in system.dll
Additional information: The underlying connection was closed: Could not establish trust relationship with remote server.
But there is a solution for this problem, you can solve this in your code by creating your own CertificatePolicy class (which implements the ICertificatePolicy interface). In this class you will have to write your own CheckValidationResult function that has to return true or false, like you would press yes or no in the dialog window. For development purposes I've created the following class which accepts all certificates, so you won't get the nasty WebException anymore:public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy{ public TrustAllCertificatePolicy() {}
public bool CheckValidationResult(ServicePoint sp, X509Certificate cert,WebRequest req, int problem) { return true; }}
As you can see the CheckValidationResult function always returns true, so all certificates will be trusted. If you want to make this class a little bit more secure, you can add additional checks using the X509Certificate parameter for example. To use this CertificatePolicy, you'll have to tell the ServicePointManager to use it:System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();This must be done (one time during the application life cycle) before making the call to your webservice.
.NET 2.0 absolute API list:
http://msdn2.microsoft.com/en-us/netframework/aa497286.aspx
Also while consulting a friend regarding new features in .NET 2.0, I found a cool link.
http://msdn2.microsoft.com/en-us/library/t357fb32.aspx
Thursday, 21 December 2006
After so long..
Today I found one nice link which used to bind 2d array to datagrid.
http://www.codeproject.com/cs/database/BindArrayGrid.asp
Today started looking at .NET 3.0 for new project.
Here is nice link for the same.
http://www.netfx3.com/
Monday, 18 December 2006
Comments on article.
for me and I started searching on msdn2. Surprisingly I came to know that Microsoft does not recommend to derive custom exception classes from System.ApplicationException rarther is says that you should derive it directly from System.Exception. In .NET 1.1 it was exactly reverse. But this approach does not add significant value addition.
Here is link from MSDN2.
http://msdn2.microsoft.com/en-us/library/ms229005.aspx
While browsing this link I was really amazed to see so much of information. I am trying to make it at one place..
There are many good articles on usage on msdn2.
Some of them are like..
Guidelines for Names:
http://msdn2.microsoft.com/en-us/library/ms229002.aspx
Type Design Guidelines:
http://msdn2.microsoft.com/en-us/library/ms229036.aspx
Member Design Guidelines:
http://msdn2.microsoft.com/en-us/library/ms229059.aspx
Designing for Extensibility:
http://msdn2.microsoft.com/en-us/library/ms229028.aspx
Usage Guidelines:
http://msdn2.microsoft.com/en-us/library/ms229035.aspx
.NET Framework Class Library Reference:
http://msdn2.microsoft.com/en-us/library/d11h6832(VS.80).aspx
Asynchronous Programming Design Patterns:
http://msdn2.microsoft.com/en-us/library/ms228969.aspx
These are too good articles and everyone should read to expand their knowledgebase.
Friday, 15 December 2006
My .NET Articles...
sites like
www.codeguru.com, www.codeproject.com.
Here are those links.
- http://www.codeguru.com/csharp/csharp/cs_syntax/errorhandling/article.php/c12971/
- http://www.codeguru.com/csharp/.net/net_general/eventsanddelegates/article.php/c12933/
- http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c11367/
- http://www.codeguru.com/csharp/csharp/cs_syntax/inheritance/article.php/c10215/
- http://www.codeproject.com/Purgatory/NET_remoting_in_chat_app.asp
- http://www.codeproject.com/useritems/Events_and_Delegates.asp
- http://www.codeproject.com/useritems/Satellite_assemblies.asp
- http://www.csharphelp.com/archives2/archive438.html
Will keep on putting more articles.
Some inspirational links I found...
http://quotations.about.com/cs/inspirationquotes/a/Success1.htm
For SQL server questions...
Add, edit, delete datagridview.
After so many days. I was busy with Sister-In-Law's marriage. Yesterday I was not able to login. Something wierd was happening. Yesterday I was fignting with simple datagridview to add, edit and delete operations. I was able to to add and edit but delete? It took me 3-4 hours to make it work anf finally I did it. The following link helped me.
http://msdn2.microsoft.com/en-us/library/5s3ce6k8.aspx
It was simple thing to do but I was trying it with datatable. But actually you can do it with
public partial class Form1 : Form
{
private const string connectionString = "Database=MyDatabase;Server=localhost;User=sa;Password=sa;Enlist=false;";
private string sqlQuery;
private SqlConnection connection;
private SqlCommand command;
private SqlDataAdapter adapter;
private SqlCommandBuilder builder;
private DataSet ds;
private DataTable userTable;
private string[] fields = { "StatusId", "ADUserId", "Email", "FirstName",
"LastName" , "JobTitle", "DepartmentId", "Phone", "Fax",
"Mobile", "UniqueKey", "IsDeleted", "CreatedByUserId", "CreatedOn",
"ModifiedByUserId" };
public Form1()
{
InitializeComponent();
SetDataObjects();
btnUpdate.Enabled = false;
}
private void SetDataObjects()
{
sqlQuery = "SELECT UserID, StatusId, ADUserId, Email, FirstName, LastName, "
+ " JobTitle, DepartmentId, Phone, Fax, Mobile, UniqueKey,"
+ " IsDeleted, CreatedByUserId, CreatedOn, ModifiedByUserId"
+ " FROM [User]";
connection = new SqlConnection(connectionString);
command = new SqlCommand(sqlQuery, connection);
adapter = new SqlDataAdapter(command);
builder = new SqlCommandBuilder(adapter);
ds = new DataSet("MainDataSet");
}
private void btnLoad_Click(object sender, EventArgs e)
{
btnLoad.Enabled = false;
try
{
if (userTable != null)
{
userTable.Clear();
}
userDataGridView.DataSource = null;
userDataGridView.Rows.Clear();
userDataGridView.Refresh();
connection.Open();
adapter.Fill(ds, "User");
userTable = ds.Tables["User"];
foreach (string field in fields)
{
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
column.ValueType = userTable.Rows[0][field].GetType();
column.DataPropertyName = field;
column.HeaderText = field.ToUpper();
column.Name = field;
column.ReadOnly = false;
column.SortMode = DataGridViewColumnSortMode.Automatic;
column.Visible = true;
switch (field.ToLower())
{
case "aduserid":
case "email":
case "firstname":
case "lastname":
case "jobtitle":
case "departmentid":
case "phone":
case "fax":
case "mobile":
break;
case "statusid":
userTable.Columns[field].DefaultValue = 1;
column.Visible = false;
break;
case "userid":
column.Visible = false;
break;
case "uniquekey":
userTable.Columns[field].DefaultValue = 1;
column.Visible = false;
break;
case "isdeleted":
userTable.Columns[field].DefaultValue = 0;
column.Visible = false;
break;
case "createdbyuserid":
userTable.Columns[field].DefaultValue = 1;
column.Visible = false;
break;
case "createdon":
userTable.Columns[field].DefaultValue = DateTime.Now;
column.Visible = false;
break;
case "modifiedbyuserid":
userTable.Columns[field].DefaultValue = 1;
column.Visible = false;
break;
}
userDataGridView.Columns.Add(column);
}
userDataGridView.DataSource = userTable.DefaultView;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
btnLoad.Enabled = true;
}
finally
{
connection.Close();
}
}
private void btnAdd_Click(object sender, EventArgs e)
{
try
{
userDataGridView.ReadOnly = false;
btnAdd.Enabled = false;
btnUpdate.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
try
{
connection.Open();
adapter.Update(userTable);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
btnAdd.Enabled = true;
btnLoad.Enabled = true;
btnUpdate.Enabled = true;
connection.Close();
}
}// Was simeple but I took little bit more time.
private void btnDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Do you really want to delete selected record(s)?",
"Delete Warning", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 0, false)
== DialogResult.Yes)
{
try
{
connection.Open();
int cnt = userDataGridView.SelectedRows.Count;
for (int i = 0; i <> 0 &&
this.userDataGridView.SelectedRows[0].Index !=
this.userDataGridView.Rows.Count - 1)
{
this.userDataGridView.Rows.RemoveAt(
this.userDataGridView.SelectedRows[0].Index);
}
}
adapter.Update(userTable);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
connection.Close();
btnLoad.Enabled = true;
}
}
}
}