Friday, November 23, 2012

Not receiving MMS w/ ting on my Samsung SIII

Symptom:  People did not receive pictures we sent and we did not receive pictures that they sent.

Environment:
Pam using a Samsung Galaxy SIII, stock rom, rooted, but without the latest patch.
James using a Samsung Galaxy SIII, CM10 rom, using cm-10-20121118-NIGHTLY

Solution for Pam's phone:

  • dial ##DATA#
  • select Edit
  • enter MSL (obtain from ting, or go to the website, find Account, Device Settings, Select the phone number, and the MSL is under it)
  • select Others
  • select MMSC URL
  • change from http://mms.sprintpcs.com to http://mms.plspictures.com
  • save and reboot


Solution for James's phone:


  • It seems there was no obvious way to natively edit the MMS setting with CM10.  Various sources indicated I needed to edit a file.  To make things easier, I installed DropBear SSH server.
    https://play.google.com/store/apps/details?id=me.shkschneider.dropbearserver
  • SSH in, then remount the file system:
    • root@android:/ # cd /system/etc
    • root@android:/system/etc # mount -o rw,remount /system
  • Using vi, I altered /system/etc/apns-conf.xml to replace references for mms.sprintpcs.com to be mms.plspictures.com
  • Rebooted, MMS now works.  Reboot may not have been necessary even.



Wednesday, October 3, 2012

Getting the Repeater row index from the LinkButton


This is one I am posting for my own reference so I can find it easier...  When Clicking a LinkButton in a Repeater, I needed the index available to modify a cached DataTable.

Situation:  Getting the Repeater row index from the LinkButton

Solution:

        LinkButton lnkButton = sender as LinkButton;
        int RepeaterItemIndex = ((RepeaterItem)lnkButton.NamingContainer).ItemIndex;

Credit to kaushalparik27 at http://forums.asp.net/t/1333400.aspx/1

Tuesday, October 2, 2012

Scroll after postback


Situation: Button inside of a GridView fires the Command event and needs to scroll to the bottom of the page.

Solution:  Use an anchor tag, then use ClientScript.RegisterStartupScript on the end of the event method to scroll to it.

Credit goes to http://forums.asp.net/t/1311972.aspx/1

Monday, August 13, 2012

SQL string splitter


I really prefer to give credit for these types of things, but I don't remember where I found it :(

Basic syntax... select dbo.FN_STRING_HELPER_SPLIT('My name is James', ' ', 4) will return 'James'



CREATE FUNCTION [dbo].FN_STRING_HELPER_SPLIT
(
  @strToSplit as varchar(4000),
  @delimiter as varchar(50),
  @columnToReturn as int
)
RETURNS varchar(25)
AS
BEGIN
  -- Declartion of the return variable
  DECLARE @i as int
  DECLARE @occurrences as int
  DECLARE @delimiterIndex as int
  DECLARE @actSplitValue as varchar(4000)
 
  -- T-SQL statements to compute the return value here
  SET @i = 1
  SET @delimiterIndex = 1
 
  WHILE @i <= @columnToReturn
  BEGIN
    SET @delimiterIndex = CHARINDEX(@delimiter, @strToSplit)
    -- if not found end while
    SET @actSplitValue = @strToSplit
    IF @delimiterIndex = 0 BEGIN
      BREAK
    END
    SET @actSplitValue = LEFT(@strToSplit, @delimiterIndex - 1)
    -- SUBSTRING(string, von, bis)
    SET @strToSplit = SUBSTRING(@strToSplit ,@delimiterIndex +1, LEN(@strToSplit)- @delimiterIndex)
    SET @i = @i + 1
  END
  -- the result of the function
  RETURN @actSplitValue
END

Friday, May 25, 2012

Rendering a UserControl as string



I was given the task of creating an HTML based email that sent the contents of a webform.  This is where I explored the possibility of rendering an independant usercontrol into a string.


I did some searching and came across code like this:

Page pageHolder = new Page();

PrintVersion pv1 = (PrintVersion)pageHolder.LoadControl("PrintVersion.ascx");

pv1.BindData();

pageHolder.Controls.Add(pv1);


StringWriter output = new StringWriter();

HttpContext.Current.Server.Execute(pageHolder, output, false);

return output.ToString();


I was getting errors like:

System.Web.HttpException: Error executing child request for handler System.Web.UI.Page'.

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.

System.Web.HttpException: Control 'ctl00_listItems' of type 'Repeater' must be placed inside a form tag with runat=server.


I stumbled on this article:




It suggested overriding a method (notice no call to the base method)


public class PageOverride : System.Web.UI.Page

{

   public override void VerifyRenderingInServerForm(System.Web.UI.Control control) {}

}


Worked perfectly!




Wednesday, May 9, 2012

Panel with a Visible property that won't update

What's wrong with this pseudo-code?

Panel p = gridItems.Rows[0].FindControl("pnlHiddenByDefault");
//do some other random stuff
gridItems.DataBind();
//do more random stuff
p.Visible = true; //FAIL

The code will execute fine but even after setting the Visible property to true, a QuickWatch will show the property is still false.

The fix:

Panel p = gridItems.Rows[0].FindControl("pnlHiddenByDefault");
//do some other random stuff
gridItems.DataBind();
//do more random stuff
//get fresh reference after DataBind
p = gridItems.Rows[0].FindControl("pnlHiddenByDefault");

p.Visible = true; //WIN

Friday, February 17, 2012

using SqlDataSource in code

Sometimes there is a need to use a SqlDataSource object in the code...

ASPX:
<asp:SqlDataSource ID="sqlSelectUsers" runat="server"
ConnectionString="<%$ConnectionStrings:MainConnectionString %>"
ProviderName="<%$ ConnectionStrings:MainConnectionString.ProviderName %>"
SelectCommandType="StoredProcedure"
    SelectCommand="spSelectUsers">

<SelectParameters>
<asp:Parameter Name="RequestingUserID" Type="Int16" />
</SelectParameters>
</asp:SqlDataSource>


VB:
sqlSelectUsers.SelectParameters("RequestingUserID").DefaultValue = 2 //hard coded value for demo purposes
Dim dv As DataView = sqlSelectUsers.Select(DataSourceSelectArguments.Empty)
Dim dt As DataTable = dv.ToTable()

This will result in a DataTable for manual consumption.

Another way to parse CSV parameters for values not necessarily in a table

-- http://www.projectdmx.com/tsql/tblnumbers.aspx
CREATE TABLE dbo.Nbrs(n INT NOT NULL IDENTITY) ;
INSERT dbo.Nbrs DEFAULT VALUES ;
WHILE SCOPE_IDENTITY() < 500 INSERT dbo.Nbrs DEFAULT VALUES ;

-- http://www.projectdmx.com/tsql/sqlarrays.aspx

DECLARE @p VARCHAR(50)
SET @p = 'ALFKI,LILAS,PERIC,HUNGC,SAVEA,SPLIR,LONEP,GROSR'

SELECT SUBSTRING( ',' + @p + ',', n + 1, CHARINDEX( ',', ',' + @p + ',', n + 1 ) - n - 1 ) AS "value"
FROM Nbrs
WHERE SUBSTRING( ',' + @p + ',', n, 1 ) = ',' AND n < LEN( ',' + @p + ',' ) ;

drop table Nbrs    

Thursday, February 16, 2012

Convert a SQL CSV Parameter into a table

Consider the need to pass in a CSV parameter like this:

DECLARE @UserIDs_CSV VARCHAR(50)
SET @UserIDs_CSV = '1,2,4,5,8,9'

If that CSV parameter happens to correlate to a table, like in this case, Users... Use a query like this to convert the CSV parameter into a temp table...

SELECT UserID
into #SelectedUserIDs
FROM Users
WHERE CHARINDEX(
',' + cast(UserID as varchar(10)) + ',',
',' + @UserIDs_CSV + ','
) > 0

So now just use the temp table as you need for future queries...

select * from #SelectedUserIDs

Credit goes to http://www.projectdmx.com/tsql/sqlarrays.aspx

Monday, February 6, 2012

Getting a quicker SQL row count

Credit goes to Rick Caminiti at http://rickcaminiti.com/tips/alternative-efficient-tables-rowcount-sql/


SELECT COUNT(*) statements make a full table scans to return the total table’s row count, it can take a lot of time and a lot of “energy” for a large table.
There is another way to determine the total row count in a table by using the sysindexes system table. There is a column (ROWS) in it that contains the total row count for each table in your database.
You can use the syntax below to speed up the query by several times.  You can see this by setting statistics on, as shown below.


SET STATISTICS IO ON
GO
SELECT count(*) FROM tbTest
GO
SELECT rows FROM sysindexes WHERE id = OBJECT_ID('tbTest') AND indid < 2
GO
SET STATISTICS IO OFF
GO



I tried my own test, and here are my results:


(1 row(s) affected)
Table 'myTable'. Scan count 1, logical reads 116, physical reads 1, read-ahead reads 176, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

(1 row(s) affected)
Table 'sysidxstats'. Scan count 1, logical reads 5, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.