2009-04-20 7 views
3

나는 교육 도메인 용 웹 사이트를 개발 중입니다. SQL Server 2008에서 Filestream을 사용하여 이진 형식의 데이터베이스에 문서 (MS Word 또는 텍스트 파일)를 저장하려고합니다. 그러나 텍스트 상자에서 문서를 검색 할 수 없습니다.filestream in SQL Server 및 C# for aspx

string path = reader.GetString(0); 
SqlFileStream stream1 = new SqlFileStream(path, (byte[])reader.GetValue(1), FileAccess.Read, FileOptions.SequentialScan, 0); 
StreamReader fs = new StreamReader(stream1); 

fs = File.OpenText(path); 
string s = fs.ReadToEnd(); 

txtInput.Text = s; 
//lblStatus.Text = "File Succesfully Read!" 
fs.Close(); 

이 코드는 데이터베이스가 아닌 파일 시스템에 저장되어있는 문서에 대한 작업 다음과 같이

내 코드입니다. 그래서 나는 다음과 같은 코드를 시도 :이 코드에서

string path = reader.GetString(0); 
SqlFileStream stream1 = new SqlFileStream(path, (byte[])reader.GetValue(1), FileAccess.Read, FileOptions.SequentialScan, 0); 
StreamReader fs = new StreamReader(stream1); 

fs = File.OpenText(path); 
string s = fs.ReadToEnd(); 

txtInput.Text = s; 
//lblStatus.Text = "File Succesfully Read!" 
fs.Close(); 

을, 그것은 "경로에 액세스가 거부되었습니다"로 라인 fs = File.OpenText(path); 에 오류가 있습니다.

도와주세요!

+0

SQL Server에서 사용하는 .MDF 파일에서 파일을 열려고합니까? –

+0

당신의 "독자"는 무엇을 포함합니까 ?? 어떤 값을 거기에서 검색합니까 ?? –

+1

제공되는 코드 스 니펫에서 차이점을 확인할 수 없습니다! – Cerebrus

답변

1

이 체크 아웃 article - SQL Server 2008의 파일 스트림 작업이 어떻게 작동 하는지를 자세히 보여줍니다.

마크

0

내 이해에 따라 Windows 인증을 통해 서버에 연결해야합니다. SQL Server 인증에서는 작동하지 않습니다. Windows 사용자는 데이터를 저장하기 위해 SQL Server에서 만든 공유 폴더에 액세스 할 수 있어야합니다.

1

stream1을 사용하여 데이터를 읽어야합니다. StreamReader 및 File.OpenText 방식은 작동하지 않으며 T-SQL 또는 SqlFileStream 개체를 사용하여 파일 스트림 데이터 만 읽을 수 있습니다.

0

두 예제 모두에서 SqlFileStream 또는 StreamReader를 사용하지 않고 File.OpenText를 사용하고 있습니다.

StreamReader fs = new StreamReader(stream1); 

fs = File.OpenText(path); 
string s = fs.ReadToEnd(); 

File.OpenText는 SQL 파일 스트림이 아닌 디스크의 파일에서만 작동하며 스트림 판독기를 사용해야합니다. 이 트릭을 수행해야합니다 :

StreamReader fs = new StreamReader(stream1); 

string s = fs.ReadToEnd();