Thursday, December 20, 2007

Year End

Well, another year is coming to an end and what a year it has been.  I have seen my Wife and daughter grow to be best little buddies.  Also my daughter learning and an incredible pace.  As for my life in the development world I took on a new job.

 

Switched from R.J. Reynolds to Bank of America in July.  This was a great move with more challenging work.  This year I can add to my resume that I am a Microsoft SharePoint 2007 Guru, Microsoft InfoPath Developer, .NET Web Service Developer, along with SQL Server Reporting Services.

 

Visual Studio 2008, so that will be my new challenge next year.

Tuesday, December 18, 2007

InfoPath - Hyper Link with data field

Not mentioned in this article is that you should create another Data Element in your infopath form, example - DynamicHyperLink

concat('http://www.website.com/index.aspx?ID=',DataField)

Be sure to then use that as your data source as indicated below.

 

Create a dynamic hyperlink in a form template

If you want a hyperlink to change depending on values in the form, you can include a dynamic hyperlink in your form template. To create this type of hyperlink, you must bind (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) the hyperlink to a field (field: An element or attribute in the data source that can contain data. If the field is an element, it can contain attribute fields. Fields store the data that is entered into controls.) in the data source (data source: The collection of fields and groups that define and store the data for an InfoPath form. Controls in the form are bound to the fields and groups in the data source.). If the design of your form requires it, you can bind the hyperlink to one field and the display text to another field.

For example, imagine that you are designing a real-estate listing form, which is connected to a database that contains information about properties that are for sale. In the database, you might have a field that contains distinct URLs for each real estate agent. In your real-estate listing form, you can insert a hyperlink and bind it to the field in the data source that contains the URL value. If you want the hyperlink to display the name of the real estate agent rather than the URL, you can bind its display text to a field in the data source that contains the name value. When users click the agent's name on the form, that agent's Web page opens in a browser window.

  1. In design mode, click in the form template where you want to insert a hyperlink, or select the text or picture that you want to turn into a hyperlink.
  2. On the Standard toolbar, click Insert Hyperlink Button image .
  3. Under Link to on the General tab, select Data source, click Select XPath Button image, and then select a field or group.
  4. Under Display, do one of the following:
    • To display a specific string of text for the hyperlink, click Text, and then in the Text box, type the text that you want to display.
    • To have a value inside a control on the form template display as the hyperlink's text, click Data source, click Select XPath Button image, and then select the field or group that the control is bound to.
  5. To assign a ScreenTip that will appear when a user rests the mouse pointer over the hyperlink, click the Advanced tab, and then, in the ScreenTip box, type the text that you want to display.

Tip  You can use XPath (XML Path Language (XPath): A language used to address parts of an XML document. XPath also provides basic facilities for manipulation of strings, numbers, and Booleans.) expressions to create hyperlinks that are a combination of static and dynamic data. For example, imagine that you want to create a hyperlink that links to "http://www.example.com/my name.html" where the Web server name, http://www.example.com, doesn't change, but the file name, my name, varies depending on the data that users type into a specific field in the form. In this case, you would type concat('http://www.example.com/', my:name, '.html') in the Data source box, where my:name is the name of the field to which the text box is bound. The Concat function allows you to combine static text with data from other fields in the form.

dbcc checkident('table_name', reseed, 0)
 
Reset Database identity

Friday, December 14, 2007

Answer Re: A transport-level error has occurred when sending the request to the server
Answer Was this post helpful ?
Reply Quote

For some reason the connection was made through Named Pipes instead of Shared Memory (the default for local connections), which suggests that SqlClient did not recognize the connection was local, and most likely tunneled Named Pipes over TCP, hence, disconnecting the network has impact. 

How do you specify the server name - perhaps by its fully qualified domain name (FQDN), or IP address? 

If you specify it by the hostname or "." or "(localhost)" SqlClient should recognize the local connection, and you should not see the error. 

Stored Procs

Please be aware if you are inserting data into a data field with a value type of int and allows null be sure to set the @Param int = null

This will prevent errors when submitting.

Wednesday, December 12, 2007

InfoPath class file from export

xsd.exe myschema.xsd /classes /l:cs /n:[NAMESPACE]

Identity Information

Introduction

 

About Identity Columns

If you have worked with SQL Server, you are probably familiar with identity columns. These are equivalent to the "AutoNumber" columns in Access. The main purpose of these columns is to provide a primary key to the table when a primary key cannot be defined using other fields in the table.

 

These columns are like any other column except that their value is not inserted by the user, but by the system itself.

Syntax

IDENTITY [ ( seed , increment ) ]

Where:

seed - Is the value that is used for the very first row that is inserted into the table.

increment- Is the incremental value that is added to the previous identity value and thereby to get new value for the new row that is going to be added.

Note: You must specify both the seed and increment or neither. If neither is specified, the default is (1,1).

 

A few things you need to know about the identity columns:

·         They should be of data type int, smallint, tinyint, decimal or numeric with scale 0.

·         They cannot contain null values

·         They cannot have any default values

·         The identity increment is an integral value (1, -1, 5, etc.) and cannot contain decimals. Also, it cannot be 0.

·         Identity Seed is 1 by default, and so is the Identity Increment. If you leave the seed field empty, it becomes 0.

 

 

Functions associated with IDENTITY column

·               @@IDENTITY
When a record is inserted into a table with an identity column, the function @@IDENTITY returns the last identity value that was inserted in the database.

Syntax

@@IDENTITY

 

I emphasize the phrase "last identity value" here because this may be different from the identity value of that particular table where the record was inserted.

Why? When a record is inserted and if there is any underlying trigger that modifies other tables, the value can be different. If a trigger adds a record into another table, which happens to have an identity column, @@IDENTITY will now return this new value instead.

 

·               Scope_IDENTITY

Returns the last IDENTITY value inserted into an IDENTITY column in the same scope. A scope is a stored procedure, function, or batch. Thus, two statements are in the same scope if they are in the same stored procedure, function, or batch. It may be more clear from the example below.

Syntax

SCOPE_IDENTITY()

 

·               IDENT_CURRENT

Returns the last identity value generated for a specified table in any session and any scope.

Syntax

IDENT_CURRENT('table_name')

 

·               IDENT_SEED

Returns the seed value specified during the creation of an identity column in a table that has an identity column.

Syntax

IDENT_SEED('table_name')

 

·               IDENT_INCR

Returns the increment value specified during the creation of an identity column in a table that has an identity column.

Syntax

IDENT_INCR('table_name')


Examples and Tips

 

Example

-- Consider the 2 Tables

CREATE TABLE Student(studId int IDENTITY(1,1), studName varchar(30))

CREATE TABLE Copy_Student(sid int IDENTITY(100,1))

GO

 

--Create trigger for insert on table Student

CREATE TRIGGER trgStudent ON Student FOR INSERT

AS

BEGIN

   INSERT INTO Copy_Student DEFAULT VALUES

END

GO

 

--Check The Tables

SELECT  *  FROM Student    --No records

SELECT  *  FROM Copy_Student --No records

GO

--Now do the following to check out the difference

 

 

INSERT INTO Student(studName) VALUES('Anjali Chelawat')

 

SELECT @@IDENTITY AS [IDENTITY]

 

--Returns the value 100, which was inserted by the trigger that is by the second insert statement.

 

 

SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY] 

 

--Returns the value 1, which was inserted by the Student table INSERT Statement before the trigger's insert statement.

 

 

SELECT IDENT_CURRENT('student') AS [IDENT_CURRENT]

 

--Returns last identity value inserted into Student.

 

 

 

SELECT IDENT_CURRENT('copy_student') AS [IDENT_CURRENT]

 

--Returns last identity value inserted into Copy_Student.

 

 

SELECT IDENT_INCR('student') AS [IDENT_INCR]

 

-- Returns the increment value of the identity column of the table Student. The value provided at the time of creation of the identity column

 

 

SELECT IDENT_SEED('student') AS [IDENT_SEED]

 

-- Returns the seed value of the identity column of the table Student. The value provided at the time of creation of the identity column

 

 

 

A Few Tips

·         Allowing inserts to identity columns:

 

If you are inserting data from some other source to a table with an identity column and you need to ensure you retain the identity values, you can temporarily allow inserts to the identity column. Without doing so explicitly you will receive an error if you attempt to insert a value into the identity column. For example, if I have a table named MYTABLE and I want to allow inserts into the identity column, I can execute the following:

Syntax

set identity_ insert  table_name on

 

Once you execute the command you will be able to insert values into the table's identity column. This will stay in effect in until you turn it off by executing the following:

 

Syntax

 

set identity_insert table_name off

 

Note: Be aware that at any time, only a single table in a session can have the identity_insert set to on.  If you attempt to enable this for a table and another table already has this enabled, you will receive an error and will not be able to do so until you first turn this off for the other table. Also, if the value used for the identity is larger than the current identity value then the new value will be used for the identity seed for the column.  

 

 

·         Reseeding the identity value:

 

You can reseed the identity value, that is, to have the identity values reset or start at a new predefined value by using DBCC CHECKIDENT.  For example, if I have a table named MYTABLE and I want to reseed the identity column to 30 I would execute the following:

 

dbcc checkident (‘table_name’, reseed, 30)

 

If you wanted to reseed the table to start with an identity of 1 with the next insert then you would reseed the table's identity to 0.  The identity seed is what the value is currently at, meaning that the next value will increment the seed and use that.  However, one thing to keep in mind is that if you set the identity seed below values that you currently have in the table, that you will violate the identity column's uniqueness constraint as soon as the values start to overlap.  The identity value will not just “skip” values that already exist in the table.

 

 

 

Points To Remember

·   IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope.

·   @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.

·   SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope.

 

Credit to:

All About IDENTITY Columns in Sql Server 2000
by Anjali Chelawat
Published on 10/5/2006

Thursday, November 29, 2007

SQL Reporting Notes

SQL Reporting Notes
 
I noticed an issue with SQL Reporting and the PDF formatting.  I was receiving a lot of extra pages between page breaks.  I realized that the grid margins had moved to be extremely wide which caused the problem.
 
If you have this problem be sure to check your margins.


If you are developing a 11" x 8.5" be sure that your grid is equal to your width minus the margin for left and right.

Example you have a report to be 11" wide with 1/2" margins this means your grid and I repeat cannot be wider than 10" or you will have blank pages and please be sure not to nudge it by accident.

Tuesday, November 27, 2007

SQL Reporting Services Expression

If you ever need to insert "data not available" or "n/a" use the following code.

=IIf(Fields!HoursAllocated.Value is nothing, "No Data Supplied", Fields!HoursAllocated.Value)

ASP.NET Account locked out please check before banging your head.

aspnet_wp.exe could not be started. The error code for the failure is 80004005. This error can be caused when the worker process account has insufficient rights to read the .NET Framework files. Please ensure that the .NET Framework is correctly installed and that the ACLs on the installation directory allow access to the configured account.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

aspnet_wp.exe could not be launched because the username and/or password supplied in the processModel section of the config file are invalid.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

 

Check the following:  Make sure the ASP.NET Machine Account is not locked out...  It will save you a lot of headaches.

Monday, November 26, 2007

%HOME%%HOMEPATH%

Have you ever needed to use RUNAS for testing security on your applications?
 
If so, and you have gotten a second account for testing and get weird errors such as not finding the application be sure to change the Start In to point to the actual executables location rather than the %HOME%%HOMEPATH%

Tuesday, November 13, 2007

Check empty array Trick

The old trick for checking for an empty array is

Dim X() As String

If (Not X) = -1 Then
Debug.Print "empty"
Else
Debug.Print "UBound is " & UBound(X)
End If

Wednesday, November 07, 2007

InfoPath and Web Services

Have you ever had this issue developing a Web service with InfoPath?

InfoPath cannot submit the form.
An error occurred while the form was being submitted.
The SOAP response indicates that an error occurred:

System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP
Header SOAPAction:http://localhost <-- Questions Have you changed the URL here but it the change does not work on the Submit for the InfoPath form?

Well first things first. Every time you update the Web service you need to re-do the connection to the Web service inside of InfoPath. I discovered this after about 2 hours of trying to find out what I was doing wrong in my code VS.NET 2005 UGH!!!!

Hack away fellow gurus.





More to come on the solution I am working on. I am thinking about creating a White Paper and I will include all Blogs that have helped me with this solution.

Wednesday, October 10, 2007

Data Types

Data types defined for SQL Server http://msdn2.microsoft.com/en-us/library/aa258271(SQL.80).aspx

Difference between varable and fixed -

When you design your tables, it helps to understand the tradeoffs of using variable length columns versus fixed length columns. Variable length columns reduce database size because they take only what is required to store the actual value. Fixed length columns always take maximum space defined by the schema, even when the actual value is empty. The downside for variable length columns is that some operations are not as efficient as those on fixed length columns. For example, if a variable length column starts small and an UPDATE causes it to grow significantly, the record might have to be relocated. Additionally, frequent updates cause data pages to become more fragmented over time. Therefore, we recommend that you use fixed length columns when data lengths do not vary too much and when frequent updates are performed (Microsoft - http://technet.microsoft.com/en-us/library/ms172432.aspx.

Unicode vs. Non-Unicode - The primary difference between unicode and non-unicode data types is the ability of unicode to easily handle the storage of foreign language characters which also requires more storage space.

Tuesday, September 11, 2007

Backup and Restore on SQL Server

thanks to moonguy on MSDN he saved me many hours of work.

When you try to backup, SQL Server 2005 shows the default backup path i.e. c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\ . This directory default has SQL user rights. Go to Backup directory and check the user name. Its very big name and I have not checked how SQL server adds it in allowed users list. You can do 2 things:



1. Let the Server take backup on default directory and copy the file in your desired folder. I did that.

2. Give same kind of permissions to your desired folder as Backup directory has.



Hope it solves the issue.



Moonguy

Tuesday, August 14, 2007

Settings.Settings .NET C#

I just learned the newest feature for adding configuration to .NET application (Console, Windows Forms, Web forms, ets.)

Settings.Settings are created when you start your application. This allows you to build out Settings that scope either the application or user. But the big question was how do you access them in the code.

Simple.

Try this

Properties.Settins.Default.[Intellisense takes over and find your setting]

That easy.

Friday, July 13, 2007

InfoPath Designer Mode

Well, after all the research I found Tim Pash as you can see in the post below. It seems that in the Corporate Enviroment you have to request that you have the setting deployed to you by your Microsoft Office Deployment and Configuration team. So with that being said, if you do not see the designer feature in InfoPath send a request to you Information Technology Team.

Wednesday, July 11, 2007

InfoPath

Well,

I am now back contracting because of my love to CODE. I have a new venture at Bank of America using SharePoint, InfoPath, and Visual Basic for Applications (VBA). My first task is to figure out how to enable InfoPath to allow me to design?

I found a great resource from the Tim Pash: http://blogs.msdn.com/timpash/archive/2006/02/08/Prevent-Design-Mode-For-Users.aspx?CommentPosted=true#commentmessage

Thursday, June 21, 2007

Update from comparison of two SQL tables

UPDATE o
SET Amount=Price
FROM orders o JOIN items i ON (o.ItemNumber=i.ItemNumber)

UPDATE o SET EmpActive = 0 FROM ComplianceEmployee o
JOIN ComplianceEmployeeLoad i ON (o.EmpID = i.EmpID)

Update from comparison of two SQL tables

UPDATE o
SET Amount=Price
FROM orders o JOIN items i ON (o.ItemNumber=i.ItemNumber)

UPDATE o SET EmpActive = 0 FROM ComplianceEmployee o
JOIN ComplianceEmployeeLoad i ON (o.EmpID = i.EmpID)

Sunday, May 20, 2007

GoDaddy.com System.Net.Mail Solution

Here is the C# version of the GoDaddy.com ASP.NET 2.0 Send Mail by Moojjoo http://www.mmwebs.com

Web.Config
<?xml version="1.0"?>

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>

<customErrors mode="Off"/>
<compilation debug="true"/> <!-- Be sure to change this to false when going to production -->

</system.web>
<system.net>

<mailSettings>
<smtp>

<network

host="relay-hosting.secureserver.net" />
</smtp>

</mailSettings>
</system.net>

</configuration>



.cs code behind for your .aspx page

protected void btnSubmit_Click(object sender, EventArgs e)
{

MailMessage myMail = new MailMessage();

myMail.From = new MailAddress("from@yourdomain.com");
myMail.Subject = "Contact Form";

MailAddressCollection myMailTo = new MailAddressCollection();
myMail.To.Add("to@domain.com");

StringBuilder sb = new StringBuilder();
sb.Append("Last Name: " + txtFirstName.Text + "<br>");

sb.Append("First Name: " + txtFirstName.Text + "<br>");
sb.Append("Address: " + txtAddress.Text + "<br>");

sb.Append("City: " + txtCity.Text + "<br>");
sb.Append("State: " + ddlState.SelectedValue + "<br>");

sb.Append("Zip: " + txtZip.Text + "<br>");
sb.Append("Email: " + txtEmail.Text + "<br>");

sb.Append("Questions/Comments: " + txtQandC.Text + "<br>");string strBody = sb.ToString();
myMail.Body = strBody;

myMail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Credentials = CredentialCache.DefaultNetworkCredentials;

try

{

smtp.Send(myMail);

myMail = null;
}

catch (System.Exception ex)
{

Response.Write(ex.Message);

}

}

Moojjoo տÕ

http://www.mmwebs.com

http://www.autoinventoryonline.com/

Sunday, January 28, 2007

ASP.NET 2.0 - Membership and Roles

Today, I have been working with SQL Server 2000 and Visual Studio 2005 to increase my speed in development by using Strongly Typed Datatypes and the Membership/Roles provided by SQL.

For now I am going to jump into using the Membership/Roles provided by ASP.NET.

Microsoft has made it easy to setup membership/role for you Web application, but did not explain the needs most freelance developers must use in order to use rented Web hosting space.

As for my self I develop on http://www.idevconsultants.com/ servers and they run SQL 2000. And not to mention I do not have keys to the server so I have to develop with what I can without making changes to IIS. This is the same for most developers.

So here is the trick to use this new membership tools.

Scott Gu blog http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx explains the ends and outs, but basically the secret is to run the following tool:

Open a command-line window on your system and run the aspnet_regsql.exe utility that is installed with ASP.NET 2.0 in under your C:\WINDOWS\Microsoft.NET\Framework\v2.0.xyz directory. This tool will build all the Tables, StoredProcs needed to run the membership tools in ASP.NET 2.0.

VERY IMPORTANT: Next in your WEB.CONFIG name your connection string to

















Again DO NOT I REPEAT DO NOT change the name...

Wednesday, January 10, 2007

Testing Visual Studio with Firefox

In my job I develop for Intranets (IE) and Internet (All Browsers) and order to test Firefox I found the following article which was crucial to setting up the Firefox browser for testing an ASP.NET 2.0 application in order to get NTLM to work.

http://brennan.offwhite.net/blog/2005/07/22/firefox-authentication-with-ntlm/

Be sure to add localhost to your proxy if needed.