Friday, June 14, 2013

SQL to get the tables and its row count

Below is the SQL we can use to get the tables and its row count.
CREATE TABLE #counts
(
    table_name varchar(255),
    row_count int
)

EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'
SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC

drop table #counts



Alternatively, can use this SQL, it will give the same result:
DECLARE @sql nvarchar(MAX)

SELECT
    @sql = COALESCE(@sql + ' UNION ALL ', '') +
        'SELECT
            ''' + s.name + '.' + t.name + ''' AS ''Table'',
            COUNT(*) AS Count
            FROM ' + QUOTENAME(s.name) + '.' + QUOTENAME(t.name)
    FROM sys.schemas s
    INNER JOIN sys.tables t ON t.schema_id = s.schema_id
    ORDER BY
        s.name,
        t.name

EXEC(@sql)


Reference: here

Thursday, June 13, 2013

[System.Web.HttpException]: {"File does not exist."}

Did you encounter this error? Dunno where exactly the error is??
Same me too..

Resolution is check your css file.
There could be an image reference from the css file that is not valid anymore.
That's the case for me.
So after I remove the css that refer to the invalid file path, it didn't give such error anymore.

Reference: here

Tuesday, May 28, 2013

Sharepoint webservice - create and get list of subfolders

To create folder
            Dim webUrl as string = "http://localhost/sites/test1/"
            Dim listWebService As New ListService.Lists()
            listWebService.Url = webUrl + "/_vti_bin/lists.asmx"
            listWebService.Credentials = System.Net.CredentialCache.DefaultCredentials 'New System.Net.NetworkCredential("user", "pwd")
            Dim doc As New XmlDocument
            Dim xmlCommand As String
            Dim node1 As XmlNode
            xmlCommand = "<Batch OnError='Continue' RootFolder='" & webUrl & "/Main'><Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='FSObjType'>1</Field><Field Name='BaseName'>" & foldername & "</Field></Method></Batch>"
            doc.LoadXml(xmlCommand)
            Dim batchNode As XmlNode = doc.SelectSingleNode("//Batch")
            node1 = listWebService.UpdateListItems("Main", batchNode)
ListService is the web service http://localhost/sites/test1/_vti_bin/lists.asmx added as reference.

If you want to add subfolder, just need to change the rootfolder on the xmlCommand.

To get the list of subfolders (this can be used to check if subfolder exists)
   Sub getSubFolders(parent As String, ByRef retTable As DataTable)
        Dim query As String = "<mylistitemrequest><Query><Where><Eq><FieldRef Name=""FSObjType"" /><Value Type=""Lookup"">1</Value></Eq></Where></Query><ViewFields><FieldRef Name=""EncodedAbsUrl""/><FieldRef Name=""ID"" /><FieldRef Name=""Title"" /></ViewFields><QueryOptions><Folder>" & parent & "</Folder></QueryOptions></mylistitemrequest>"
        Dim dt As DataTable = Nothing
        Console.WriteLine("Parent is " & parent)
        Using listProxy As ListService.Lists = New ListService.Lists()
            listProxy.Url = webUrl + "/_vti_bin/lists.asmx"
            listProxy.UseDefaultCredentials = True

            Dim doc As XmlDocument = New XmlDocument()
            doc.LoadXml(query)

            Dim queryNode As XmlNode = doc.SelectSingleNode("//Query")
            Dim viewNode As XmlNode = doc.SelectSingleNode("//ViewFields")
            Dim optionNode As XmlNode = doc.SelectSingleNode("//QueryOptions")

            Dim retNode As XmlNode = listProxy.GetListItems("Main", String.Empty, queryNode, viewNode, String.Empty, optionNode, Nothing)

            Dim ds As DataSet = New DataSet()
            Using sr As StringReader = New StringReader(retNode.OuterXml)
                ds.ReadXml(sr)
            End Using



            If Not IsNothing(ds.Tables("Row")) Then
                If ds.Tables("Row").Rows.Count > 0 Then
                    Dim folderUrls = From f In ds.Tables("Row").AsEnumerable() Select f("ows_EncodedAbsUrl")
                    dt = ds.Tables("Row").Copy()

                    For Each folderUrl As String In folderUrls
                        getSubFolders(folderUrl, dt)
                    Next

                    retTable.Merge(dt)
                End If
            End If

        End Using

    End Sub

Comment the getSubFolders(folderUrl, dt) if you do not want to drill down the subfolders.

Subfolders references: here and here

Tuesday, May 7, 2013

ODP.NET oracleexception with no error message :S

My oracle version is 11.2.0.2.

I tried to use ODAC 11.2.0.3 to connect to the database from my .net program.
And it threw this error ORA-1017: invalid username/password; logon denied when my password expires and I tried to change my password.

So I installed ODAC 11.2.0.2 and try to connect to the database in VB.Net however I got error OracleException with no error message -> Oracle.DataAccess.Client.OracleException: {""}

But when I code my program in C# it gave the error OracleException {"ORA-28001: the password has expired"}

Solution to this is to uninstall all the ODAC versions in my PC.
Then install ODAC 11.2.0.2 and now it should work fine.

Btw in order to change password when the password expired, u can use this method OpenWithNewPassword.

See my thread at Oracle forum here.

 

Monday, April 29, 2013

Configuration system failed to initialize

Got this error?

Check your web.config or app.config, make sure that comes after

So it should be like this:

<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <appSettings>
    <add key="ConfigXMLPath" value="D:\Config.xml" />
  </appSettings>
...
</configuration>

If your configSections does not come right after , it will throw such error.

Example of configuration that will throw the error:

<configuration>
  <appSettings>
    <add key="ConfigXMLPath" value="D:\Config.xml" />
  </appSettings>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
...
</configuration>

Thursday, April 18, 2013

Check SQL version from Query

Just type this

SELECT @@VERSION VersionInfo
GO

:D
source: here

Thursday, November 29, 2012

.NET App does not read columns with blank and non-blank values in excel

My .net application that uploads excel file does not read columns with blank and non-blank values in excel.


In this case, system detects that first row is blank, hence it determines it as string, however for the first non-blank row, system detects it as numbers (different from the previous rows), hence system will not store the fields and show it as Null.




This problem is caused by a limitation of the Excel ISAM driver in that once it determines the datatype of an Excel column, it will return a Null for any value that is not of the datatype the ISAM driver has defaulted to for that Excel column. The Excel ISAM driver determines the datatype of an Excel column by examining the actual values in the first few rows and then chooses a datatype that represents the majority of the values in its sampling. (http://support.microsoft.com/kb/194124)


Solution:
1) Add IMEX=1 into your excel connection
http://forums.asp.net/t/1802376.aspx/1
2) Try using .xlsx, it should work with Microsoft.ACE.OLEDB.12.0
3) If you are using .xls, try putting the non-blank values records first before the blank values records in the excel.