Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Does StreamReader open file readonly?
Message
From
14/11/2009 17:31:01
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 8.0
Miscellaneous
Thread ID:
01434675
Message ID:
01434786
Views:
37
>>Hi,
>>
>>The ADODB obect probably tries to use read/write permissions when opening the file so try FileShare.ReadWrite
>>HTH,
>>Viv
>>
>
>If I understand correctly, your advise is to apply FileShare.ReadWrite in on option for StreamReader:
>
>Dim fs1 As System.IO.FileStream = New System.IO.FileStream(lcfilename, System.IO.FileMode.Open,
> System.IO.FileAccess.Read, System.IO.FileShare.Read)
>Dim lcDataText As New System.IO.StreamReader(fs1)
>
>
>And instead of System.IO.FileShare.Read in dim fs1... above use FileShare.ReadWrite.
>
>
>No, it did not work.
>
>
>Below is what I am doing exactly with ADODB. No matter I run this code from VFP, or from VB.NET, RecordSet fails
>to open and with the message (attached).
>
>SrcDTW  = "bpdtw.txt"
>pcxdir = "\\pcsNAS01\brdpcx\prod\datafile\"
>
>cnnText = CreateObject("ADODB.Connection")
>cnnText.mode= 16  && adModeShareDenyNone
>cnnText.Open("Provider=Microsoft.Jet.OLEDB.4.0;" +;
>       "Data Source=" + pcxdir + [;Extended Properties="text;HDR=NO;FMT=FixedLength"])
>
>rst_DTW  = CreateObject("ADODB.Recordset")
>adLockReadOnly = 1
>adOpenStatic = 3
>adUseClient = 3
>rst_DTW.CursorLocation = adUseClient
>rst_DTW.Open("select * from " +SrcDTW+ " WHERE GRADE <>' ULTRA' ORDER BY 3,4", cnnText, adOpenStatic, adLockReadOnly)
>
>?rst_DTW.recordcount
>
>rst_DTW.close
>cnnText.close
>
>
>Any idea, what is wrong? I am using shema.ini file to allow ADODB to see the TXT file structure. Is it possible it is somwehow involved?


Yuri,
Did you read my reply on Foxite? The culprit is using ADO on a text file. No matter what the mode is, it is ADO who is opening the file exclusively. StreamReader is innocent and really opens as readonly.

PS: Schema.ini has no role. With or w/o it ADO would lock the file.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform