.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Jean Paul
SP
satyapriyanayak
ASPEvil
Ashutosh Jha
Post New Web Links

Reading and Writing Files in SQL Server using T-SQL

Posted By: Syed Shakeer Hussain     Posted Date: December 02, 2010    Points: 2   Category :Sql Server
 
SQL Server has never been short of ways to read from and write to files and it is always better to use the standard techniques provided by SQL Server where possible. However, most of them are really designed for reading and writing tabular data and aren't always trouble-free when used with large strings or relatively unstructured data.

For reading tabular data from a file, whether character-delimited or binary, there is nothing that replaces the hoary old Bulk Copy Program (BCP), which underlies more esoteric methods such as Bulk Insert. It is possible to read text-based delimited files with ODBC, simple files can be read and written-to using xp_cmdshell, and you will find that OSQL is wonderful for writing results to file, but occasionally I've found I need to do more than this.

Thankfully, when armed with OLE Automation and the FileSystem Object (FSO), all sorts of things are possible. The FileSystem Object was introduced into Windows to provide a single common file-system COM interface for scripting languages. It provides a number of handy services that can be accessed from TSQL. In this article, I provide examples of stored procedures that use this interface to allow you to:


View Complete Post


More Related Resource Links

SQL Server 2008 r2 - Setup support files - Install error / reading from file

  

I'm installing SQL server 2008 r2 on a Win2003 R2 x86 system.

After i start the setup, the "setup support files" box begins installing, after a while i get this error:

"Error reading from file f:\1033_ENU_LP\x86\setup\sqlsupport_msi\PFiles\SqlServr\100\Setup\ewbfphdh\x86\Patch\rs2000.msp verify that the file exists and that you can access it."

I've tried another DVD, i've tried a mounted share on another machine...no go....i've tried an ISO file mounted on this server... same error.

Is there any way i can install this "setup support files" from another location? (download)

Is there a switch soo it won't install reporting services? (...i think this file rs2000.msp is from reporting services)

Thanks

Pipas

 

 


The reading of visual fox pro files (.dbf) does not work if the server has more that 1 GB of RAM

  
I am reading .dbf files using openrowset instructions, but it does not work if the files are bigger that 250MB. I been looking a lot for information and doing tests. At the end I tested with all my development enviroment mounted in a virtual machine and I discovered something really rare. If the RAM assigned to de virtual machine is 1 GB, the openrowset query works fine, no matter how big is the .dbf file(I tested with 1.5 GB files and it works fine). So my question is if somebody knows if is necesary some special configurations in SQL Server 2005 for to work in a server with 4 processors and 4 GB of RAM. The error message that appears when the server memory exceeds 1 GB is the next:

Msg 7399, Level 16, State 1, Line 1
El proveedor OLE DB "MSDASQL" para el servidor vinculado "(null)" informó de un error. El proveedor no proporcionó información acerca del error.
Msg 7320, Level 16, State 2, Line 1
No se puede ejecutar la consulta "SELECT d2,d3,d4,d5,d6,d7,d8,d9,d10,d10_2,d11,d12,d17,d18,d18_2,d18_3,d23,d13 FROM tadat_gigante.dbf" en el proveedor OLE DB "MSDASQL" para el servidor vinculado "(null)".

the query is the next:

SELECT * FROM OPENROWSET('MSDASQL',
    'Driver=Microsoft Visual FoxPro Driver; SourceDB=c:\; So

Reading and Writing Images From a Windows Mobile Database using UltraLite 10(C#)

  
Periodically I get a request for information on how to read and write binary data to a database running on Windows Mobile. If you search the Internet you can typically find examples that are available on Windows Desktops or allow you to read and write to a local file system. The problem is that it can take a bit of work to get this code to work on Windows Mobile accessing a database.

Ultimately you might be asking, why would I want to store and image in a database? Well in an environment where you synchronizing data between a local mobile database and a consolidated (central) database this can be extremely useful. Imagine if an insurance adjuster went to an accident scene, took a picture of a damaged car, loaded it into his Windows Mobile database and then replicated that image up to the Insurance headquarters for approval. All of this could be done in a very short period of time when using images in the database. Another good example might be a doctor who was waiting for a patient chart to become available. If you could store the image in a database this chart could be sent down to the doctor's device once it became available.

For this article I am not going to get into how to synchronize the images to and from a remote and central database as this is typically fairly straightforward when using a data synchronization technologies like MobiLink

XML Reading and Writing

  
We learned to process XML files using the Document Object Model as implemented by the XmlDocument class. To go further and make XML friendlier, the .NET Framework provides many other classes for different purposes, allowing you to create and manage nodes from custom .NET classes.
Besides the XmlDocument and the derived classes of XmlNode, the .NET Framework provides the XmlTextWriter class, which is derived from XmlWriter. The XmlTextWriter class works in a top-down approach to create, or deal with, the contents of an XML file. This class writes an XML node and moves down without referring

dynamically adding sql server columns based on number of files in fileuploader

  

I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.

 

I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!

 

Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")

objConn.Open()

connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly.

  

I dont have the SQL EXPRESS installed instead I have SQL Standard Edition.

 I have two SQL Server instances installed.

 1- UserLT (this is sql 2000)
2- UserLT\SQL2005 (this is SQL 2005 named instance)

But when i try to add a database to my VS website project I get the following error:

Connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly. please verify the installation of the component or download from the URL: go.microsoft.com/fwlink/?linkId=4925

I went in Tools>Opetions>DataBase tools>Data Connection>Sql Server Instance Name (blank for default)

and changed the "SQLEXPRESS" to "USERLT\SQL2005".

But I still get the same error message. Any ideas how i can resolve this issue?


reading values from config files in NUnit tests

  

One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?


Copying files to a folder on web server

  

Hi

I have few files in FolderA on the web server.

I want the users to select a fews files from FolderA and copy them to FolderB on the same web server.

I want to list all the files in FolderA and allow the user to select a few files and copy.

I want to copy the files programatically when the user selects a few files and click on Copy button.

How to copy the files quickly from folderA to FolderB?

thanks

Ashok

 


Reading/writing Word documents - keeping formatting

  

I've done some reading about reading from and writing to a Word doc. The reading from worked without issue:

string strPath = "Test.doc";
FileStream fStream = new FileStream
    (strPath, FileMode.Open, FileAccess.Read);
StreamReader sReader = new StreamReader(fStream);
string text = sReader.ReadToEnd();
sReader.Close();


But of course this is just a string, without any formatting information included. Writing to the document using a StreamWriter worked, but I received errors when opening the document.

I've also read that trying to perform actions on an Office document on a server without the Office products installed on it can result in mayhem. I'm working on a MVC application that will allow users to upload documents to the server, work on them, save their work and email it around. That doesn't specifically require the need to read/write programmatically, but for certain application functions I do need this. Any helpful suggestions are appreciated.


how to upload files (5MB-50MB) into sql server 2008 by using filestream

  
Hi!i have some files, and i need to upload these files into sql server 2008 by using filestream.lets take table name as custfiles,              columns are fileid,filename,filepath,filesize.1.how to create table using filestream?2.how to insert file (record) into table from .net environment?3.how to retrive that file from .net environment?please provide related code....THANS FOR ANY HELP

FtpWebRequest - how to upload two files on FTP server using only one connection?

  
Hi I am using FtpWebRequest with option KeepAlive = true. When I upload first file I create ftp request object: FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create("ftp://10.10.6.104/lcsroot//inpt//Test//file1.xml"); I set KeepAlive = true and I do upload file. When I want upload second file I have to create new FtpWebRequest object using new URI FtpWebRequest result = (FtpWebRequest)FtpWebRequest.Create("ftp://10.10.6.104/lcsroot//inpt//Test//file2.xml");   I set KeepAlive = true and I do upload file. The problem is that I have to create new FtpWebRequest so I create new connection to FTP server (I have checked using netstat -b command that my application uses another port number for second file). How can I upload two files (or more) using only on FTP connection/session? Regards  

Multiple XML files into SQL SERVER Express 2005

  
Hello. I am familiar with classic ASP and use this with MS SQL SERVER EXPRESS. I have an SQL table and want to import multiple XML files into this on a daily basis. I currently have 3 files, transferdata.vbs which loops through the XML files. FAQschema.xml which maps XML to the SQL database and test.xml shows the xml in the test file. If I run transferdata.vbs I get the following error "Error opening the data file" line 33 char 3. Microsoft Bulkload for SQL Server". My SQL table is called EnqOrd id (int), Debitor (varchar), PurchaseDate (varchar)     transferdata.vbs set objBL = CreateObject("SQLXMLBulkLoad.SQLXMLBulkLoad") objBL.ConnectionString = "Provider=SQLOLEDB; Data Source=XXXXXX\XXXXX; Initial Catalog=XXXX; User ID=XXXXX; Password=XXXXXX" objBL.ErrorLogFile = "E:\fuelsql\Teccom\error.log" ' Here is the path to your XML files Const path = "E:\fuelsql\Teccom\XML\" Dim Text, Title, oFile Dim fso, oFolder, oFiles, wsh ' Object variables Text = "Folder " Title = "XML Files" Set wsh = WScript.CreateObject("WScript.Shell") ' Create FileSystemObject object to access the file system. Set fso = CreateObject("Scripting.FileSystemObject") ' Get Folder object. Set oFolder = fso.GetFolder(wsh.ExpandEnvironmentStrings(path)) ' Get All Files Set oFiles = oFolder.

Import Multiple XML files into Sql Server

  
Hi, i have nearly 1000 xml files in one folder of similar format and I have xsd for the same as well. I would like to import all the files in to sql table by either looping through all the files or any other way. Thanks
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend