Thursday, March 10, 2016

SP_CHANGEDBOWNER Error Msg 15110

Msg 15110, Level 16, State 1, Line 1
The proposed new database owner is already a user or aliased in the database.

The error message gives a hint at what is wrong.  The user is already present.  So, let's delete (drop) the user and then change the owner back to the user we really want to be the owner of the database. 


USE YourDB
GO
SP_DROPUSER ‘The_User’ — Drop The_User 
GO
SP_CHANGEDBOWNER ‘The_User’ — Change the owner 

Tuesday, December 15, 2015

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'.

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).


If you've received that error while trying to run a Microsoft ASP.NET webform, then you can easily fix the problem.  Add the following snippet in your web.config file.

<appSettings>
   <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />     
</appSettings>

After you add the key to your web app, everything should work fine.

Wednesday, August 26, 2015

Padding with Leading Zeros

How do you pad a string in SQL with leading Zeros (0)?

Sometimes you have numbers like:

0
2
20
30
350

If you want the numbers to all line in and pad with zeros then you can use the REPLICATE function in SQL Server to accomplish this:

REPLICATE('0', 3 - LEN(YOUR_FIELD))

The 3 in the statement above is how many characters should be.  After running the REPLICATE, you should get this:

000
002
020
030
350

Plus, they are now easier to sort.

VAL Function in SQL Server

Is there a something similar to the VAL function in SQL Server?

I had someone complain that they could not sort on the value of a field and that their sort was wrong.  They sent me this list: (ID)

8, 10, 11, 20, 30, 45, 9.

When they did the ORDER BY ID, the list came out like this;

10, 11, 20, 30, 45, 8, 9

It looks like their ID is a character and hence ASCII sorting will take place but if they write the SQL query like this;

SELECT ID from TblAccounts
ORDER BY CAST(ID as Int)

The result is then as expected 8, 9, 10, 11, 20, 30, 45.

Programmers are familiar with VAL("some number string") in access or Visualbasic. The SQL CAST or CONVERT should work.

Tuesday, July 8, 2014

Crystal Reports Shows Blank Report

Crystal Reports Viewer shows a blank report on the production server but works on the development server.

The report was displaying fine and then it started to display a blank screen. This is the only thing that worked since crystal reports didn't show an error message or any other sign. I downloaded the latest version from the SAP website:

http://scn.sap.com/docs/DOC-7824

An interesting note is that the references show a version Version=13.0.2000.0
but it was really version 13.0.9.1312.  This was confusing and had me trying to uninstall and clear out the 13.0.2

Possible Solution:
Copy the folder aspnet_client to the root of your application on the server.

My Web.config file has the following:
<?xml version="1.0"?>
<configuration>
 <configSections>
        <sectionGroup name="businessObjects">
            <sectionGroup name="crystalReports">
                <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler"/>
            </sectionGroup>
        </sectionGroup>
    </configSections>
     <appSettings>
         <add key="CrystalImageCleaner-AutoStart" value="true" />
         <add key="CrystalImageCleaner-Sleep" value="60000" />
         <add key="CrystalImageCleaner-Age" value="120000" />
     </appSettings>
     <businessObjects>
        <crystalReports>
            <crystalReportViewer>
                <add key="UseBrowserLocale" value="true"/>
                <add key="resourceURI" value="~/aspnet_client/system_web/4_0_30319/crystalreportviewers13"/>
            </crystalReportViewer>
        </crystalReports>
    </businessObjects>
  
  <system.web>
      <httpHandlers>
          <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
      </httpHandlers>
    <compilation debug="true">
      <assemblies>
        <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
        <add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
      <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></assemblies>
    </compilation>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  <handlers>
    <add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>
  </handlers></system.webServer>
    
</configuration>








C# Optional Arguments

How do you implement optional arguments or parameters in c#?
An easy way to do this is:

public boolean isValidFName(string FName, int MinLength = 0)
{
    if (FName.Length == 0 || FName.Length < MinLength)
       return false;
    else
       return true;
}



if (isValidFName(txtFName.Text))
{
    //Only checks that the first name is not length 0.
}


if (isValidFName(txtFName.Text, 5))
{
    //Checks that the first name is at least length of 5.
}


Monday, November 25, 2013

Unrecognized tag prefix or device filter 'asp'

SOLVED FINALLY!!!

I kept receiving the warning. Unrecognized tag prefix or device filter 'asp' in my Visual Studio 2012, 2013.

I tried deleting everything in the bin directory, obj directory, deleting the suo file and the same thing.  Nothing worked.  I then realized that this WAS using master pages and I just had removed the content tags so that I could test right away.

When I put the standard html in the index.aspx page like so, everything was able to build fine.

<html>
<head>
<title></title>
</head>
<body>

My Code block here

</body>
</html>

Monday, March 18, 2013

Convert String Date to SQL Date

If you need to convert a date that is in a string format:

03/18/13

into a SQL Server Date so that you can process it, ORDER BY, etc.. then do the following:

CAST(HIRE as Datetime)

where HIRE is a date in string format. If you want to display the date in a particular format, then just CONVERT it to the format you want:

CONVERT(CHAR(10),CAST(HIRE as Datetime),101) as Hire_Date

The CHAR(10) saves space for 10 characters and the 101 is one of the formats available. I didn't use VARCHAR because the field is exactly 10 characters.  See the link below for a format you want to use if you don't like the 101 format (mm/dd/yyyy)




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


Sunday, August 26, 2012

Using a Dropdown with Yes No instead of 1 or 0 in a GridView

Showing Yes or No instead of 1 or 0 in GridView
So you have a table that you are using and instead of storing "Yes," or "No," you're using 1 to signify yes, and a 0 to signify no.  When you display the data in your ASP.NET gridview, you want it to show YES in the column or NO.  In addition, when entering edit mode you want the user to be able to select YES or NO from the dropdown instead of using 1 or 0.

You don't have to have another sqldatasource to bind a yes or a no.  Try this solution and let me know if this works for you.

<asp:TemplateField HeaderText="YOUR_FIELD" SortExpression="YOUR_FIELD">
    <EditItemTemplate>
        <asp:DropDownList ID="dropYesNo" runat="server" SelectedValue='<%# Bind("YOUR_FIELD") %>' >
            <asp:ListItem Value="0">No</asp:ListItem>
            <asp:ListItem Value="1">Yes</asp:ListItem>
        </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
        <%#Eval("YOUR_FIELD").ToString() == "1" ? "Yes" : "No" %>
    </ItemTemplate>
    <HeaderStyle HorizontalAlign="Center" />
    <ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>


Of course, the field that you want needs to be converted to a TEMPLATE FIELD.  Let me know if you don't know how to do that and I'll help or post how to.

Yes or No binds from DropDown
Notice the text YOUR_FIELD, that is what you call your 0,1 value field meaning what you want to display as Yes or No in the gridview.  In my case it was "Show."  Whether I want the item to show on my website live or no. Replace this with the name of your field that you are using.

I use
 <%#Eval("YOUR_FIELD").ToString() == "1" ? "Yes" : "No" %> 
 the EVAL to test if the field is 1 or 0 to show Yes or No in the gridview.  I put this in the ItemTemplate.

Also notice,

<asp:ListItem Value="0">No</asp:ListItem>
<asp:ListItem Value="1">Yes</asp:ListItem>

So that your 0 and 1 are written back to your table when you click update.

Happy Coding... :)
   


Friday, April 13, 2012

YouTube Video Has Green Background

YouTube Green Screen
If you play a video on YouTube and all you see is a green screen background but you can hear the audio then you may be able to solve the problem by right-clicking on the video.  The Adobe Flash Player Settings will appear on the screen.  Click on the 1st icon at the bottom that looks like a monitor (Display), then UN-CHECK the option that says, "Enable hardware acceleration"

Refresh your browser and your YouTube video should start playing normally.