Tuesday, February 28, 2012

Oracle related Issues

1:- In cmd check "echo %PATH%"  to get the environment variables with path .
2:-Start - Run - %windir%\SysWOW64\odbcad32.exe to get the providers registered with 32 bit.
3:-First time we r installing Oracle client need to configure tns names through NetConfigurationWizard.It will generate one tnsnames file in that specific location .IT contains the server name and all details.

Export to CSV

HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Buffer =
TrueHttpContext.Current.Response.AddHeader(
HttpContext.Current.Response.Charset =
"content-disposition", "attachment;filename=GLAmountsExport.csv")""HttpContext.Current.Response.ContentType = "application/text"
dt = GetXRefDataPageWise()
Dim dt As DataTable' GridView1.AllowPaging = False' GridView1.DataBind()

sb.Append(dt.Columns(k).ColumnName +
Dim sb As New StringBuilder()For k As Integer = 0 To dt.Columns.Count - 1","c)Nextsb.Append(vbCr & vbLf)


sb.Append(dt.Rows(i)(k).ToString +
For i As Integer = 0 To dt.Rows.Count - 1For k As Integer = 0 To dt.Columns.Count - 1","c)Nextsb.Append(vbCr & vbLf)
NextHttpContext.Current.Response.Output.Write(sb.ToString())
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()

Need to add  ","+c to display the values correctly in csv file .

Wednesday, February 8, 2012

IIS 7.0 Regarding issue in asp.Net Application

Junk data when convert binary to string

Here is the example :
Step 1: when I convert this string to binary I got the below output.
SELECT CONVERT(varbinary(max), '(DAYSBETWEENREADINGS(''SNOT'') * 100 / 365)')
Output:
0x28444159534245545745454E52454144494E47532827534E4F542729202A20313030202F2033363529

But in the table from which I am trying to convert binary to string I am having other than this, but sql server still returning the same string.

select CONVERT(varchar(max), 0x28444159534245545745454E52454144494E47532827534E4F542729202A20313030202F203336352900080030000000000000000000000000000000FFFF010000001C0001000000000000000000000000000000060007002A0000000000000000000000000000000100030000002B000200000000000000000000000000020000000000280001000000000000000000000000000100020000001A0000000000000000005940000000000100000000001B0001000000000000000000000000000100040005001A0000000000000000D076400000000001000000000002002800000000000000000000002B00140000000000000000001900444159534245545745454E52454144494E475300534E4F540000)
OutPut:
(DAYSBETWEENREADINGS('SNOT') * 100 / 365)


How to truncate the unnecessary sequence from binary data?


Solution :

For i = 0 To ds.Tables(t).Rows.Count - 1
                    dr = dt.NewRow()
                    For j As Integer = 0 To ds.Tables(t).Columns.Count - 2
                        If Not IsDBNull(ds.Tables(t).Rows(i)(j)) Then
                            If ds.Tables(t).Columns(j).DataType.Name = "Byte[]" Then

                                ss = "select convert(varchar(max),convert(varbinary(max),@byteArray)) as binarystr;"
                                cmd = New SqlCommand(ss.ToString, conn)
                                da1 = New SqlDataAdapter(cmd)
                                commonds = New DataSet
                                cmd.Parameters.Add("@byteArray", Data.SqlDbType.Image).Value = ds.Tables(t).Rows(i)(j)
                                da1.Fill(commonds)
                                If commonds.Tables(0).Rows.Count > 0 Then
                                    binarystr = commonds.Tables(0).Rows(0).Item(0)
                                    dr(j) = binarystr.Substring(0, binarystr.IndexOf(vbNullChar)) ‘We just done the substring, with the vbnullchar.

                                End If
                            Else
                                dr(j) = ds.Tables(t).Rows(i)(j)
                            End If
                        End If
                        commonds.Dispose()
                    Next
                    dt.Rows.Add(dr)
                Next
            Next
                     DataGridView1.DataSource = dt

IIS 6 Metabase and IIS 6 Configuration Compatibility

Getting this error when we are trying to open a .Net web application  in windows 7 .

 To access local IIS Web sites, we need to run Visual Studio in the context of an administrator account

  •     In Windows 7 or Vista , click Start, click All Programs, and then locate Visual Studio.
  •     Right-click Microsoft Visual Studio, and then click Run as administrator.





you need to install the "IIS Metabase and IIS6 Configuration Compatibility" feature under Internet Information Services-Web Management Tools-IIS 6 Management Capability to get the IIS6 ADSI provider installed.

  • First of all , you should have sufficient administrative access to turn or turn off windows features.

  • If you have the admin previliges , Please go to control panel in Windows and select Programs as shown in figure below.










  • In the settings page that opens, please select Turn windows features on or off .

  • Now go to Internet Information Services and then :
    • Expand Web Management Tools, expand IIS 6 Management Compatibility, and then select the IIS 6 Metabase and IIS 6 configuration compatibility check box.
    • Expand World Wide Web Services, expand Application Development Features, and then select the ASP.NET check box.
    • Expand World Wide Web Services, expand Security, and then select the Windows Authentication check box.
    • To enable Visual Studio to debug applications, you must configure IIS 7.0 with the Windows Authentication module. By default, the module is not configured as part of IIS.
    • Click OK to start the IIS and ASP.NET installation process.
    •  If you have resolved the above two, and still get the third error, Your project has been configured to work with IIS. Either you dont have IIS 6 metabase installed or your virtual directory is not configured as a application.

       This is something very smallish but this is something that IIS 7 + has brought in. Well in IIS 6 its just a virtual directory setup thats enough to run a application. But in IIS 7 , you have to make it as a application as well.
       Right click on your virtual directory and click on Convert to Application and you should get rid of this.


  • Wednesday, February 1, 2012

    Code to create & Write to a Text file

    Below code is to create and write text to a text file



     string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                string fileLoc = mydocpath + @"\myEventLogSource_Pathwaytest.txt";
                StreamWriter sw;
                if (!File.Exists(fileLoc))
                {
                    sw = new StreamWriter(File.Open(fileLoc, FileMode.Create));               }
                else
                {
                    sw = new StreamWriter(File.Open(fileLoc, FileMode.Append));
                }  
    sw.Write("Hello");
    sw.Dispose();