Click here to Skip to main content
15,878,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m trying to store my data(txt format)in SQL server database but when I created virtual directory for it, its working only on my sytem (on which my database and the code exist).

I am writing this code in vb.net, please check for any error.


Design file
XML
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="readingtext.aspx.vb" Inherits="readingtext" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%--<b>Raw File Output</b><br />--%>
    <center>
<asp:label id="LblMsg" runat="server" />
<br />
<asp:TextBox  ID="txtbox1" runat="server" Text=""></asp:TextBox>
<%--<p>
<u><b>Data Of Text File</b></u><br /></p>
<asp:label runat="server" id="lblNicerOutput" Font-Name="Verdana" />--%>

<br />
<asp:Button ID="Btn1" Text="PostTosql" runat="server" />
</center>
    </div>
    </form>
</body>
</html>






code file:
VB
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Web.UI

Imports System.Web.UI.WebControls
Imports System.Text
Imports System.Configuration
Imports System.Xml
Imports System.Data
Imports System.Drawing
Imports System.IO
Partial Class readingtext
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'If Not IsPostBack Then
        '    LblMsg.Text = String.Empty
        '    txtbox1.Text = String.Empty
        'End If



    End Sub

    Protected Sub Btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Btn1.Click
        Try
            Dim objSRFile As StreamReader
            Dim strInput, arrStrInput() As String
            Dim intCurrPos As Integer
            Dim strName As String
            Dim Age As String
            Dim RollNo As String
            strName = String.Empty
            Age = String.Empty
            RollNo = String.Empty
            'Dim intSalary As Integer
            'DB vars
            Dim strSQL As String
            Dim strConnString As String = ConfigurationManager.ConnectionStrings("MyCon").ConnectionString()
            Dim Con As New SqlConnection(strConnString)
            Dim objCmd As SqlCommand
            File.OpenText(txtbox1.Text)
            objSRFile = File.OpenText(txtbox1.Text)
            ' objSRFile = File.OpenText("x:\path\to\file.txt")
            While objSRFile.Peek <> -1
                strInput = objSRFile.ReadLine
                arrStrInput = Split(strInput, ",", , CompareMethod.Text)
                For intCurrPos = 0 To arrStrInput.Length - 1
                    Select Case intCurrPos
                        Case 0
                            strName = arrStrInput(intCurrPos)
                        Case 1
                            Age = arrStrInput(intCurrPos)
                        Case 2
                            RollNo = arrStrInput(intCurrPos)
                    End Select
                Next
                strSQL = "insert into InsertDataNew(Name,age,RollNo) values('" & strName & "', '" & Age & "', '" & RollNo & "')"
                objCmd = New SqlCommand(strSQL, Con)
                Con.Open()
                objCmd.ExecuteNonQuery()
                LblMsg.Text = "Data has Entered Successfully"
                Con.Close()
            End While
            objSRFile.Close()
        Catch ex As Exception
            Trace.Write(ex.Message)
        End Try
        'File to string vars
    End Sub
End Class
Posted
Updated 7-Sep-10 21:42pm
v2

All permissions are assigned properly ,
but it is not working yet.
 
Share this answer
 
Comments
Simon_Whale 29-Sep-10 12:28pm    
what is it doing instead?
what error messages does it show?
Do you have a problem when you deploy it to another machine? I think you're saying this is the problem.

If it works locally, make sure the account that the web server runs under has read/write permission in your data directory in the target deployment environment.

Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900