|
|
|
из БД на диск
|
|||
|---|---|---|---|
|
#18+
не получается выгрузить в файл на диск хранящийся в таблице файл в двоичной форме: string source = @"Data source=sergm\sergm;" + "Initial Catalog=document; Integrated security=SSPI"; SqlConnection sqlcon = new SqlConnection(source); SqlCommand com = new SqlCommand(); com.CommandText = @"select [document] from doc where id_doc=12"; com.Connection = sqlcon; FileStream fs; long retval; BinaryWriter writer; int bufferSize = 100; byte[] document = new byte[bufferSize]; long startIndex = 0; sqlcon.Open(); SqlDataReader reader = com.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()) { fs = new FileStream(@"d:\test10.odt", FileMode.OpenOrCreate, FileAccess.Write); startIndex = 0; retval = reader.GetBytes(1, startIndex, document, 0, bufferSize); while (retval == bufferSize) { writer.Write(document); writer.Flush(); startIndex += bufferSize; retval = reader.GetBytes(1, startIndex, document, 0, bufferSize); } writer.Write(document, 0, (int)retval - 1); writer.Flush(); writer.Close(); fs.Close(); } reader.Close(); sqlcon.Close(); помогите пожалуйста ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 19.04.2007, 13:46 |
|
||
|
из БД на диск
|
|||
|---|---|---|---|
|
#18+
извиняюсь, вот этот: string source = @"Data source=sergm\sergm;" + "Initial Catalog=document; Integrated security=SSPI"; SqlConnection sqlcon = new SqlConnection(source); SqlCommand com = new SqlCommand(); com.CommandText = @"select [document] from doc where id_doc=12"; com.Connection = sqlcon; FileStream fs; long retval; BinaryWriter writer; int bufferSize = 100; byte[] document = new byte[bufferSize]; long startIndex = 0; sqlcon.Open(); SqlDataReader reader = com.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()) { fs = new FileStream(@"d:\test10.odt", FileMode.OpenOrCreate, FileAccess.Write); writer = new BinaryWriter(fs); startIndex = 0; retval = reader.GetBytes(1, startIndex, document, 0, bufferSize); while (retval == bufferSize) { writer.Write(document); writer.Flush(); // Reposition start index to end of last buffer and fill buffer. startIndex += bufferSize; retval = reader.GetBytes(1, startIndex, document, 0, bufferSize); } writer.Write(document, 0, (int)retval - 1); writer.Flush(); writer.Close(); fs.Close(); } reader.Close(); sqlcon.Close(); ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 19.04.2007, 13:55 |
|
||
|
из БД на диск
|
|||
|---|---|---|---|
|
#18+
ошибка: Index was outside the bounds of the array. ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 19.04.2007, 14:01 |
|
||
|
из БД на диск
|
|||
|---|---|---|---|
|
#18+
string source = @"Data source=sergm\sergm;" + "Initial Catalog=document; Integrated security=SSPI"; SqlConnection sqlcon = new SqlConnection(source); SqlCommand com = new SqlCommand(); com.CommandText = @"select [document] from doc where id_doc=16"; com.Connection = sqlcon; FileStream fs; long retval; BinaryWriter writer; int bufferSize = 100; byte[] document = new byte[bufferSize]; long startIndex = 0; sqlcon.Open(); SqlDataReader reader = com.ExecuteReader(CommandBehavior.SequentialAccess); while (reader.Read()) { if (File.Exists(@"D:\test10.odt")) File.Delete(@"D:\test10.odt"); fs = new FileStream(@"d:\test10.odt", FileMode.OpenOrCreate, FileAccess.Write); writer = new BinaryWriter(fs); startIndex = 0; retval = reader.GetBytes(0, startIndex, document, 0, bufferSize); while (retval == bufferSize) { writer.Write(document); writer.Flush(); startIndex += bufferSize; retval = reader.GetBytes(0, startIndex, document, 0, bufferSize); } writer.Write(document, 0, (int)retval - 1); writer.Flush(); writer.Close(); fs.Close(); } reader.Close(); sqlcon.Close(); теперь ошибка при открытии файла: файл поврежден, попытаться восстановить его? после восстановления ничего в файле не обнаруживаю ... |
|||
|
:
Нравится:
Не нравится:
|
|||
| 19.04.2007, 14:54 |
|
||
|
|

start [/forum/topic.php?fid=17&fpage=96&tid=1352846]: |
0ms |
get settings: |
9ms |
get forum list: |
17ms |
check forum access: |
3ms |
check topic access: |
3ms |
track hit: |
58ms |
get topic data: |
8ms |
get forum data: |
2ms |
get page messages: |
33ms |
get tp. blocked users: |
1ms |
| others: | 218ms |
| total: | 352ms |

| 0 / 0 |
