PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > Importing images to SQL Server 2005 Express Edition database
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Importing images to SQL Server 2005 Express Edition database

Réponse
 
LinkBack Outils de la discussion
Vieux 05/09/2007, 09h30   #1
pompair
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Importing images to SQL Server 2005 Express Edition database

Hi,

Could someone give a pointer how to import couple of hundred images
into Sql Server 2005 Express Edition database?

Is there a tool for it? Can it be done with Sql Management Studio or
is it just a matter of writing own piece of software (a little er
app) to do it?

-timonardo

  Réponse avec citation
Vieux 05/09/2007, 13h49   #2
Dan Guzman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Importing images to SQL Server 2005 Express Edition database

> Could someone give a pointer how to import couple of hundred images
> into Sql Server 2005 Express Edition database?
>
> Is there a tool for it? Can it be done with Sql Management Studio or
> is it just a matter of writing own piece of software (a little er
> app) to do it?


Below is a sample VBScript that will import all files in the specified
folder. This will work for SQL 2000 and SQL 2005. You can tweak this for
your needs. You can also use OPENROWSET in SQL 2005 (see Books Online), but
you'll need to provide your own method to provide the list of files to be
imported.

Const adOpenKeyset = 1
Const adLockOptimistic = 3
Const adTypeBinary = 1

Function Main()

Set conn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
Set fso = CreateObject("Scripting.FileSystemObject")
Set strm = CreateObject("ADODB.Stream")

'change connection string
ConnectionString = "Provider=SQLOLEDB" & _
";Data Source=MyServer" & _
";Initial Catalog=MyDatabase" & _
";Integrated Security=SSPI"

conn.Open ConnectionString
'change table and column names
rs.Open "SELECT File_Name, File_Contents FROM dbo.MyTable",
conn,
adOpenKeyset,
adLockOptimistic

'change folder name
Set folder = fso.GetFolder("C:\MyFiles")
Set fileList = folder.Files
For Each file In fileList
InsertFile(file.Name)
Next

conn.Close

Main = DTSTaskExecResult_Success

End Function

Sub InsertFile(FileName)

strm.Type = adTypeBinary
strm.Open
strm.LoadFromFile FileName
rs.AddNew
'change column names
rs.Fields("File_name") = FileName
rs.Fields("File_Contents") = strm.Read
rs.Update
strm.Close

End Sub

--
Hope this s.

Dan Guzman
SQL Server MVP

"pompair" <timonardo@gmail.com> wrote in message
news:1188981057.587680.44900@19g2000hsx.googlegrou ps.com...
> Hi,
>
> Could someone give a pointer how to import couple of hundred images
> into Sql Server 2005 Express Edition database?
>
> Is there a tool for it? Can it be done with Sql Management Studio or
> is it just a matter of writing own piece of software (a little er
> app) to do it?
>
> -timonardo
>


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h02.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07320 seconds with 10 queries