Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

how do I get streamwriter to work on server?

Posted on 2008-11-06
9
Medium Priority
?
250 Views
Last Modified: 2012-05-05
I have a file that needs to be created on another server other than the one the stramwriter app is running on. I have tested the link on my local with the link to the correct server, but when I put the application in dev, I get an webunhandled acception.

any help would be much appreciated...code in snippet
strSql11 = "Select FromDate,ToDate,MeterNumber,MeterNumberSub,ConvertedMCF,ConvertedMMBTU from itpwork where FromDate>= '" & FromDate & "' and ToDate<= '" & ToDate & "' "
        cmd = New MySqlCommand(strSql11, conn)
        da = New MySqlDataAdapter(cmd)
        ds11 = New DataSet()
        da.Fill(ds11)
 
        'localhost
        'DataTable2CSV(ds11.Tables(0), "K:\saIT\ITWORK.txt")
 
        'Development Server
        DataTable2CSV(ds11.Tables(0), "\\fs1.services.etc.lan\saIT\ITWORK.txt")
 
        'Production(Server)
        'DataTable2CSV(ds11.Tables(0), "f:\inetpub\ftproot\trucktickets\ITWORK.txt")
        conn.Close()
 
    End Sub
    Sub DataTable2CSV(ByVal table As DataTable, ByVal filename As String)
        DataTable2CSV(Table, filename, vbTab)
    End Sub
    Sub DataTable2CSV(ByVal table As DataTable, ByVal filename As String, _
        ByVal sepChar As String)
        Dim writer As System.IO.StreamWriter = Nothing
        Try
            writer = New System.IO.StreamWriter(filename)
 
            ' first write a line with the columns name
            Dim sep As String = " "
            Dim builder As New System.Text.StringBuilder
            'For Each col As DataColumn In table.Columns
            'builder.Append(sep).Append(col.ColumnName)
            'sep = sepChar
            'Next
            'writer.WriteLine(builder.ToString())
 
            ' then write all the rows
            For Each row As DataRow In table.Rows
                sep = ""
                builder = New System.Text.StringBuilder
 
                For Each col As DataColumn In table.Columns
                    builder.Append(sep).Append(row(col.ColumnName))
                    sep = sepChar
                Next
                writer.WriteLine(builder.ToString())
            Next
        Finally
            If Not writer Is Nothing Then writer.Close()
        End Try
    End Sub

Open in new window

0
Comment
Question by:bschave2
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:melmers
ID: 22897707
Are the security settings right. has the asp.net account write rights on the server and the share ?
0
 

Author Comment

by:bschave2
ID: 22897769
yes, I have full access to the server and folder. It works fine on my machine with the server path, but when I put it on a server, it bombs.
0
 
LVL 11

Expert Comment

by:melmers
ID: 22897816
when you do it on your machine and the webserver runs under your user it has your rights but when it runs under the webserver account it has only the rights of the asp.net instance.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:bschave2
ID: 22897866
if I am trying to save the file on a network drive, would I need to do this. What would I need to save the file on the network?
0
 
LVL 11

Expert Comment

by:melmers
ID: 22898772
It's the same there are no difference if you save the file on a network drive or on the network with the unc path. look at the security setting of the destination folder.
Add there the ASP.NEt USer form your network server or create a AD Group where you add the ASP.NET account of your server and then add it to the security tab of the destination folder.
0
 

Author Comment

by:bschave2
ID: 22898785
I get this error when trying to copy the file from the server the app is running on to the network drive of choice.

ERROR:
The account used is a computer account. Use your global user account or local user account to access this server.
0
 
LVL 11

Accepted Solution

by:
melmers earned 2000 total points
ID: 22902128
Ok, when you have access to the server create a user who have access to the webserver and to your fileserver then create a new apppool and give him the identity of your created user.

On your website configuration set your website the new created apppool.
0
 

Author Comment

by:bschave2
ID: 22952770
I found the issue. IIS NTSF wasn't set to basic.
0
 

Author Closing Comment

by:bschave2
ID: 31513992
I will award you the point. thanks for trying to help
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question