Convert multiple Images to varbinary in SQL Server from vb.net - sql-server

I just want to know the possible ways to convert like 2 or 3 images into a varbinary and save it in a single column named images in SQL Server. And retrieve it like the way to retrieve a single image.

If you simply need to store file data in the database, and the files are accessible to the SQL Server, then you can get SQL Server to do the heavy lifting using OPENROWSET:
SELECT o.BulkColumn
FROM OPENROWSET(BULK N'C:\Myfilepath.jpg', SINGLE_BLOB) o
SQL Server will return a single-column, single-row dataset that will contain the binary data for your file.
You can use the above statement stand-alone, in a stored procedure or as part of an INSERT statement.

Related

Import arbitrary XML to SQL Server

Is that possible to parse and import an arbitrary XML file to SQL Server tables using C#?
The XML file can be highly hierarchical.
I have 1 Gb XML-file, I do not know anything about it.
How can I determine what tables it contains, create them at SQL Server and bulk load the data to SQL Server?
Is that possible?
No.
XML and SQL are very, very different things. It is possible to take SQL data an save it into XML, and such SQL-like XML can be converted back to an SQL database, but arbitrary XML that did not originate in an SQL-like system is not likely to be easily convertible to an SQL database schema in any meaningful way.
You could work out an SQL schema that represents generic XML in a key-value type design but it would not be an SQL schema in the traditional meaning of the word.

SQL BULK INSERT with on the fly table creation

I would like to use BULK INSERT to load a few hundred raw data tables into SQL Server. The format of these tables would be similar, although not identical (they come from excel sheets which are not tightly version controlled).
I want to know if there is a way to dynamically generate the table required on SQL Server depending on the headers in the file to be loaded, and then do the BULK INSERT thereafter.
You can connect to those Excel tables using OPEN ROWSET. Then, do the following:
SELECT *
FROM Excel
INTO NewTable
WHERE 0=1
This will transfer the schema. Is this what you want?
You can make an excel script that generates sql statements for creation of the tables, then execute the file before bulk insert the data.

Join two different types of databases together

I have two databases, one MSSQL and the other in Access.
Right now, inside the access file, the mssql tables are set up as linked tables so queries can be written using tables from both databases. (e.g. "select * db1.table1 where db1.table1.somevalue not in db2.table1", or select into tables like that one)
These queries need to be moved into a VB.NET project, but still be linked to the access file.
I think what I am needing is a Database object that can have tables from 2 different connections, (ie the SqlClient and OleDb connections)
Is this possible? If so, how? Or do I need to rewrite the queries using loops or something?
What I would do is query your access database to get some result set and that pass that result set as a parameter to a stored procedure in your MS SQL database. You would just have to transform your results from access into XML to be passed as a xml variable as a parameter. And then in your stored procedure you can convert the XML to be a table variable and you can use it just like a regular table.
THere is no reason you can't create an MS Access .mdb with Links to your MS Access Database and your SQL Server database
Access Db #1 Contains Access Tables and Data.
SQL Db Contains your MS SQL Tables.
Access Db #2 contains links to the tables in Access DB #1 as well as links to the tables in your SQL Server Db. This .mdb files ALSO contains your query defs required by your vb.net project.
I'm pretty sure you can just connect to the Access database. All the internal objects--including the links to SQL Server tables--should be accessible to your vb.net project.

extract xml from image column in sql server

I have some xml documents stored as an image data type in a sql server 2000 table. How can I extract the data back to xml and save to a file, or at least see the xml contents in the query window, using just the sql tools?
Look, here
Essentially you want to extract text from varbinary.

Proxy tables SQL Server vs SQL Server

We have 2 databases and we need data to be transferred from db 1 to db 2. How can I do that (in SYBASE there are proxy tables) in SQL Server?
As #Nathan says just BULK INSERT the data. Assuming both databases are on the same server then you reference the table usually as databasename.schema.tablename thus db1.dbo.table1 or db2.dbo.table1
As such you can also just create a view in the destination data to use as a 'proxy' and pull the data without actually copying it. The view would be in db2 and be something like:
CREATE VIEW table1 AS SELECT * FROM db1.dbo.table1
I think INSERT INTO would be a good way to go.
http://msdn.microsoft.com/en-us/library/aa933206(v=sql.80).aspx
First of all, you can create a linked server in your destination server to the other server. Then you can do the INSERT INTO.
If you don't want to do that (or are unable), then dump the data to a file and do the very fast BULK INSERT to get the data into your new table.

Resources