Tuesday, November 25, 2008

VS 2008 Crystal Report Viewer Zooming Problem

Problem encountered: After Zooming in/out a few times, the page resolution get stucked at some point and won't re-zoom back.

Solution:
Remove the databinding.

protected void Page_Load(object sender, EventArgs e)
{

ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("Reports/TestCrystalReport.rpt"));

ReportViewer.ReportSource = rd;
//ReportViewer.DataBind(); -->remove this line to fix the error

}

Friday, October 10, 2008

Problem with users after restoring from another database?

Error 15023: User already exists in current database.

1) This is the best Solution.
First of all run following T-SQL Query in Query Analyzer. This will return all the existing users in database in result pan.

USE YourDB
GO
EXEC sp_change_users_login 'Report'
GO

Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Auto_Fix’ attribute will create the user in SQL Server instance if it does not exist. In following example ‘ColdFusion’ is UserName, ‘cf’ is Password. Auto-Fix links a user entry in the sysusers table in the current database to a login of the same name in sysxlogins.

USE YourDB
GO
EXEC sp_change_users_login 'Auto_Fix', 'ColdFusion', NULL, 'cf'
GO

Run following T-SQL Query in Query Analyzer to associate login with the username. ‘Update_One’ links the specified user in the current database to login. login must already exist. user and login must be specified. password must be NULL or not specified

USE YourDB
GO
EXEC sp_change_users_login 'update_one', 'ColdFusion', 'ColdFusion'
GO

2) If login account has permission to drop other users, run following T-SQL in Query Analyzer. This will drop the user.

USE YourDB
GO
EXEC sp_dropuser 'ColdFusion'
GO

Create the same user again in the database without any error.

Stored Procedure 1:

/*Following Stored Procedure will fix all the Orphan users in database
by mapping them to username already exist for user on server.
This SP is required when user has been created at server level but does
not show up as user in database.*/
CREATE PROCEDURE dbo.spDBA_FixOrphanUsers
AS
DECLARE @username VARCHAR(25)
DECLARE GetOrphanUsers CURSOR
FOR
SELECT UserName = name
FROM sysusers
WHERE issqluser = 1
AND (sid IS NOT NULL
AND sid <> 0x0)
AND SUSER_SNAME(sid) IS NULL
ORDER BY name
OPEN GetOrphanUsers
FETCH NEXT
FROM GetOrphanUsers
INTO @username
WHILE @@FETCH_STATUS = 0
BEGIN
IF @username='dbo'
EXEC sp_changedbowner 'sa'
ELSE
EXEC sp_change_users_login 'update_one', @username, @username
FETCH NEXT
FROM GetOrphanUsers
INTO @username
END
CLOSE GetOrphanUsers
DEALLOCATE GetOrphanUsers
GO

Stored Procedure 2:

/*Following Stored Procedure will fix all the Orphan users in database
by creating the server level user selecting same password as username.
Make sure that you change all the password once users are created*/
CREATE PROCEDURE dbo.spDBA_FixOrphanUsersPassWord
AS
DECLARE @username VARCHAR(25)
DECLARE @password VARCHAR(25)
DECLARE GetOrphanUsers CURSOR
FOR
SELECT UserName = name
FROM sysusers
WHERE issqluser = 1
AND (sid IS NOT NULL
AND sid <> 0x0)
AND SUSER_SNAME(sid) IS NULL
ORDER BY name
OPEN GetOrphanUsers
FETCH NEXT
FROM GetOrphanUsers
INTO @username
SET @password = @username
WHILE @@FETCH_STATUS = 0
BEGIN
IF @username='dbo'
EXEC sp_changedbowner 'sa'
ELSE
EXEC sp_change_users_login 'Auto_Fix', @username, NULL, @password
FETCH NEXT
FROM GetOrphanUsers
INTO @username
END
CLOSE GetOrphanUsers
DEALLOCATE GetOrphanUsers
GO

Stored Procedure 3:

----Following Stored Procedure will drop all the Orphan users in database.
----If you need any of those users, you can create them again.
CREATE PROCEDURE dbo.spDBA_DropOrphanUsers
AS
DECLARE @username VARCHAR(25)
DECLARE GetOrphanUsers CURSOR
FOR
SELECT UserName = name
FROM sysusers
WHERE issqluser = 1
AND (sid IS NOT NULL
AND sid <> 0x0)
AND SUSER_SNAME(sid) IS NULL
ORDER BY name
OPEN GetOrphanUsers
FETCH NEXT
FROM GetOrphanUsers
INTO @username
WHILE @@FETCH_STATUS = 0
BEGIN
IF @username='dbo'
EXEC sp_changedbowner 'sa'
ELSE
EXEC sp_dropuser @username
FETCH NEXT
FROM GetOrphanUsers
INTO @username
END
CLOSE GetOrphanUsers
DEALLOCATE GetOrphanUsers
GO


Reference: Pinal Dave

Thursday, October 9, 2008

Deleting a Project in TFS 2008


TFSDeleteProject [/q] [/TeamFoundationServer:] [/force]

[/q] - Quiet mode. Do not prompt the user for confirmation.
[/TeamFoundationServer:] - The hostname of the team foundation server. (Only necessary when using more then one team foundation server in your environment.
[/force] - Indicates the program should continue even if some parts cannot be deleted.
- The name of the project. Use quotation marks if there are spaces in the name.

DELETE permission on the project is required.

sample: tfsdeleteproject /q /force /server:Adventureworks storeFront

You can find TFSDeleteProject at \Program Files\Visual Studio 9\Common7\IDE\.

=End of blog=

SQL Server Reporting Server (SSRS) service is failing to start

I was trying to create a new project using team edition when I encountered an error stating that I wasn't able to create a new project because my reporting services is not running.. blah blah blah

So I run the services.msc through run command and start the service manually, but unfortunately the process always fails after clicking the start button and before reaching half of the progress bar...googling the error I found out this solution. This might of help others experiencing the same problem.

To resolve this issue, increase the time-out value for service startup process. Increasing the value, the service will have more time to loading when the computer starts.

Subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
Name: ServicesPipeTimeout
Type: REG_DWORD
Data: The number of milliseconds that you want to give the services to start in

Typically, a data value of 30,000 is sufficient enough to keep the service from timing out. Hence, you can reduce or increase this value according to your specific startup requirements. To create this registry entry follow these steps below:

1. Click Start, click Run, type regedit, and then click OK.
2. Locate and then click the following registry subkey:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control

3. Right-click Control, point to New, and then click DWORD Value.
4. In the New Value #1 box, type ServicesPipeTimeout, and then press ENTER.
5. Right-click ServicesPipeTimeout, and then click Modify.
6. Click Decimal, type the number of milliseconds that you want to wait until the service times out, and then click OK.

For example, to wait 60 seconds before the service times out, type 60000.

7. Quit Registry Editor, and then restart the computer.

Friday, September 19, 2008

Problem Opening SharePoint Server Alert in Outlook 2007

This problem occurs because Exchange 2003 cannot convert the MIME-type properties to MAPI-type properties correctly if the names of the properties begin with X-.

You cannot open a SharePoint Server 2007 notification message in Outlook 2007 when your mailbox is on an Exchange 2003 server.

The hotfix is available via customer support. The hotfix applies to Exchange Server 2003 and has to be applied after it has been upgraded to SP2.

http://support.microsoft.com/kb/930807/en-us

Friday, September 12, 2008

Send Mail with Asp.Net {C#}

//1. Send Simple Mail in Asp.Net without any credentials (Host, Username or password)

using System.Net.Mail;

public static void SendMail(string From, string To, string Body, string Subject)
{
SmtpClient objSmtpClient = new SmtpClient();

// Give SMTP Server name here.
objSmtpClient.Host = ConfigurationManager.AppSettings["SmtpServer"].ToString();
objSmtpClient.Port = 25;

MailMessage objMailMessage = new MailMessage();
MailAddress objMailAddress = new MailAddress(From);
objMailMessage.From = objMailAddress;
objMailMessage.To.Add(To);
objMailMessage.Subject = Subject;
objMailMessage.IsBodyHtml = true;
objMailMessage.Body = Body;
objMailMessage.Priority = MailPriority.High;

objSmtpClient.Send(objMailMessage);
}

//2. Send Mail in Asp.Net with credentials (Host, Username or password)

using System.Net.Mail;

public static void SendMail(string From, string To, string Body, string Subject)
{

// give SMTP Server Host name or IP Address.
SmtpClient objSmtpClient = new SmtpClient(”HostNameOrIP”);

MailMessage objMailMessage = new MailMessage();
MailAddress objMailAddress = new MailAddress(From);
objMailMessage.From = objMailAddress;
objMailMessage.To.Add(To);
objMailMessage.Subject = Subject;
objMailMessage.IsBodyHtml = true;
objMailMessage.Body = Body;
objMailMessage.Priority = MailPriority.High;

// Give your SMTP Server UserName and Password
objSmtpClient.Credentials = new System.Net.NetworkCredential(”UserName”, “Password”);

objSmtpClient.Send(objMailMessage);

{C#} Simple Encrypt and Decrypt String

//Encrypt Method

private string EncryptString(string strSource)
{
Byte[] b = System.Text.ASCIIEncoding.ASCII.GetBytes(strSource);
string encryptedString = Convert.ToBase64String(b);
return encryptedString;
}

// Decrypt Method

private string DecryptString(string strSource)
{
Byte[] b = Convert.FromBase64String(strSource);
string decryptedString = System.Text.ASCIIEncoding.ASCII.GetString(b);
return decryptedString;
}

C# Convert String into Proper Case

Convert a string to Proper Case
===========================

// Use this Namespace
using System.Globalization;
// Code
string myString = "jEssE PaTricio-jR";
TextInfo TI = new CultureInfo("en-US",false).TextInfo;
Response.Write (TI.ToTitleCase( myString ));

Thursday, September 4, 2008

Connection String - Using sqlDataReader

It's been awhile since my last post. Now I'm currently doing some asp .net projects again and I can't remember the connection string and commands I've previously used to manually connect and get data from my source, hence, I would post it here as a reference so I don't have to search again and again for the source code.

Assuming that i have my sql server connectionstring configured on my web.config file and my stored procedure named "valStudentProfile" with two varchar parameters "username" and "password" created on my SQL Server 2005.

VB Code

Imports System.Data.SqlClient

'-- this function will validate user and return true or false
'-- by calling stored procedure and passing parameters.

Function AuthenticateUser(ByVal Username As String, ByVal Password As String) As Boolean

Dim oConn As New SqlConnection

oConn.ConnectionString = ConfigurationManager.AppSettings("MyServerName")
oConn.Open()

Dim oComm As New SqlCommand
oComm.Connection = oConn

oComm.CommandType = CommandType.StoredProcedure
oComm.CommandText = "valStudentProfile"

Dim pUser As New SqlParameter("@username", SqlDbType.VarChar)
Dim pPass As New SqlParameter("@password", SqlDbType.VarChar)

pUser.Value = UserName.ToString()
pPass.Value = Password.ToString()

oComm.Parameters.Add(pUser)
oComm.Parameters.Add(pPass)

Dim rd As SqlDataReader = oComm.ExecuteReader()

rd.Read()

'- validate if have records
If rd.HasRows Then
'- initialize my session variable
Session("userid") = rd.Item("userid").ToString()
'return true if record exist in the database
Return True
Else
'- return false if no record found match
Return False
End If
-- disposing objects
oComm.Dispose()
oConn.Dispose()
End Function


C# Code


public authUser()
{
string username = txtUsername.ToString();
string password = txtPassword.ToString();

SqlConnection oConn = SqlConnection(ConfigurationManager.AppSettings["MyServerName"]);
conn.open();

SqlCommand oComm = new SqlCommand("valStudentProfile", oConn);

oComm.CommandType = CommandType.StoredProcedure;
oComm.Parameters.Add("@username", SqlDbType.VarChar).Value = username;
oComm.Parameters.Add("@password", SqlDbType.VarChar).Value = password;

SqlDataReader rd = oComm.ExecuteReader();

if (rd.Read())
{
return true;
} else {
return false
}
}

Thursday, July 10, 2008

Can not add the user because a user with that name already exist

These is a very common error in sharepoint 2003, so I've decided to post it here for future references.

Symptoms: When you try to add a user to a Microsoft Office Sharepoint Portal Server 2003 portal site or to a Microsoft Windows Sharepoint Services Web site that is hosted on the portal site, you receive the following error message:

Problem: "Can not add the user because a user with that name already exist"

Cause:
This issue may occur if the following conditions are true:
1. You create a user account in the Active Directory service.
2. You add the user to the portal site or to the windows sharepoint services web site.
3. You delete the user accoint from Active Directory. You then create a new user account that uses the same logon name as the user account that you deleted.
4. You try to add the new user account that you created in Active Directory.

Resolution:

To resolve this issue, connect to the Manage Site Collection Users page, and then remove the existing user account. After you do this, add the new user to the portal site or to the Windows SharePoint Services Web site. To do this, follow these steps:
1.
Use on of the following methods to connect to the Manage Site Collection Users page:

To connect to the Manage Site Collection Users page of the portal site, type the following address in the address bar of your Web browser, and then press ENTER:
http://ServerName/_layouts/1033/Siteusrs.aspx Note The Manage Site Collection Users page is not revealed in the SharePoint Portal Server 2003 user interface. You have to manually connect to the page.

To connect to the Manage Site Collection Users page of a Windows SharePoint Services Web site that is hosted on the portal site, type the following address in the address bar of your Web browser, and then press ENTER:
http://ServerName/Sites/SiteName/_layouts/1033/Siteusrs.aspx
2.
Click to select the check box that is next to the name of the user who you want to remove, and then click Remove Selected Users. Note If more than 100 users are in the site collection, the user may not be listed on the current page. To view additional users, scroll to the bottom of the list of users, and then click Next.
3.
Click OK when you are prompted to confirm the removal.

http://support.microsoft.com/?kbid=893696&FR=1

Wednesday, July 9, 2008

Sequencing 2007 office programs in Microsott

Some interesting guidance for sequencing...

Prescriptive guidance for sequencing 2007 office programs in Microsoft Softgrid
http://support.microsoft.com/default.aspx?scid=kb;EN-US;939796

Best practices to use for sequencing in Microsoft Softgrid
http://support.microsoft.com/kb/932137

Sunday, July 6, 2008

Drop failed for Job Maintanenance

I just ran into an error prompting "Drop failed for job maintenance" and use the script below to remove this old maintenance plan for my db server.





Problem: Unable to delete the plan and the job always prompting error conflicting constraint.

Solution: run the sql script below on your query window.

USE [msdb]

declare @job_name varchar(100)
set @job_name = N'MaintenancePlan'


–First, delete the logs for the plan

delete sysmaintplan_log
FROM sysmaintplan_subplans AS subplans INNER JOIN
sysjobs_view AS syjobs ON subplans.job_id = syjobs.job_id INNER JOIN
sysmaintplan_log ON subplans.subplan_id = sysmaintplan_log.subplan_id
WHERE (syjobs.name = @job_name)


–delete the subplan

delete sysmaintplan_subplans
FROM sysmaintplan_subplans AS subplans INNER JOIN
sysjobs_view AS syjobs ON subplans.job_id = syjobs.job_id
WHERE (syjobs.name = @job_name)


–delete the actual job (You can do the same thing through Management Studio (Enterprise Manager)

delete
from msdb.dbo.sysjobs_view where name = @job_name


If you get this error:

Msg 547, Level 16, State 0, Line 27
The DELETE statement conflicted with the REFERENCE constraint “FK__sysjobsch__job_i__276EDEB3″. The conflict occurred in database “msdb”, table “dbo.sysjobschedules”, column ‘job_id’.

Open the Job and Delete the Schedules

Tuesday, July 1, 2008

How to display icons in a document library

You will notice that when uploading a file to a document library the default icon image is not displayed properly.

This procedure will guide you to display the image of your file to sharepoint file system.

I will use pdf file as an example.

1. obtain a pdf icon of your choice.
2. rename the image icpdf.gif
3. copy the image to this directory "c:\program files\common files\microsoft shared\web server extensions\60\template\images" on each front-end web server.
4. edit the docicon.xml file located in "c:\program files\common files\microsoft shared\web server extensions\60\template\xml" folder.
5. add this code to your docicon.xml "file
6. restart IIS

Browse to your document library with a pdf document and check if the icon is displayed properly. If you don't see the icon right away just click refresh(F5).

Thursday, June 26, 2008

Installing 2008 Team Foundation Server

I was tasked to install Team foundation server 2008 on a server machine so i thought that I should jot down bit by bit my progress in this endeavor for future references. So started out with the installation documention and pre-requisites.

Install MS SQL Server 2005 Standard or Enterprise

Download and install SQL 2005 service pack 2
http://www.microsoft.com/downloads/details.aspx?FamilyId=d07219b2-1e23-49c8-8f0c-63fa18f26d3a&displaylang=en

Downloaded KB925673 patch for MSXML 6.0 parser (You won't be needing this if you updated the SQL with patch SP2)
http://www.microsoft.com/downloads/details.aspx?FamilyID=fd513435-fa6d-407c-bedc-5fd03e5b7d6c&DisplayLang=en

Wizard walkthrough:
1. run setup command

2. You may want to read the installation guide and I suggest you do so before proceeding with the actual installation.

Choose Team foundation server and click install.



3. You can choose to send information to microsoft and click next to continue.

4. Tick and agree with the lincense terms and click next.


5. Confirm the destination folder and click next.

6. Select SQL database server and click next.

7. Processing system health check.


8. Choose service account. I selected the default system account and clicked next.

9. Select a different account for your reporting services and click next.

10. You can either install a new or redirect to an existing sharepoint services and click next.


11. Specify account for sharepoint services and click next


13. You can enable the alert setting now or later.

14. Team foundation is now ready to install. click install.

15. Installing components status...

16. Setup completed successfully!

I hope you'll find this topic significant to your solutions.

Can not add the user because a user with that name already exists

Problem:
Can not add the user because a user with that name already exists

Solution:
http://ServerName/_layouts/1033/Siteusrs.aspx Note The Manage Site Collection Users page is not revealed in the SharePoint Portal Server 2003 user interface. You have to manually connect to the page.
Click to select the check box that is next to the name of the user who you want to remove, and then click Remove Selected Users.

http://support.microsoft.com/kb/893696

MOSS 2007: Service unvailable error when accessing Sharepoint 3.0 Central Administration

Problem:
Error
Retrieving the COM class factory for component with CLSID {3D42CCB1-4665-4620-92A3-478F47389230} failed due to the following error: 8007042d.


Solution:
1. Type on run command: secpol.msc
2. On Security Setting > Local policies > User rights assignments
3. Look for object titled "Log on as service" and click it.
4. Add user or group that should have access for the services in sharepoint.