Usinf OPENROWSET To Read From A .ttx File

Mar 5, 2008


I have a .ttx file similar to this:

"xxxxxxxxx" "dc8" "184:30" "168:00" "00:00" "00:00" "00:00" "00:00" "00:00" "00:00" "00:00" "00:00" "00:00" "00:00" "00:00" 0 0 0 1

I want to read from this file from T-SQL, I saw in a previous post that its possible to do it using OPENROWSET (http://msdn2.microsoft.com/en-us/library/ms190312.aspx)

I don€™t have a clue what parameters i must use on the OPENROWSET T-sql command (provider name to ttx ?)

I would appreciate if anyone could give an example of how to do this

Thanks !

View 7 Replies


ADVERTISEMENT

How To Read CSV File In SQL Server 2005 Using OpenRowSet Function

May 4, 2007

Hi

i want to access a CSV file using OpenRowSet function in SQL Server 2005.



Anyone having any idea; would be of great help.

Regards,

Salman Shehbaz.

View 8 Replies View Related

SQL 2012 :: OPENROWSET To Read In Data From Excel 2010 File (XLSX)

Jun 12, 2015

I have a test server (TEST1) running SQL 2012 and Windows 2012R2. One of the developers wants to use OPENROWSET to read in data from an Excel 2010 file (an xlsx file).

I have loaded the Microsoft Drivers in "AccessDatabaseEngine_64.exe" and enabled the Ad Hoc Distributed Queries option in SQL.

This is the sample code we are working with:

SELECT
X.MEMBID
FROM OPENROWSET(
'MSDASQL',
'Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=etworkserverFolder1Folder2MEMBIDs.xlsx',
'SELECT * FROM [Sheet1$]'
) AS X

I can run the sample query from my laptop with SSMS (I have admin rights) and I can also run it as SA from my laptop. So all is good, right?

But if I RDC into TEST1, I cannot run the query. I get this error:

OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Excel Driver] Your network access was interrupted. To continue, close the database, and then open it again.".
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Excel Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x574 Thread 0xb74 DBC 0x1d07f08 Excel'.".
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Excel Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0x574 Thread 0xb74 DBC 0x1d07f08 Excel'.".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".But wait! It gets better.

I can run the query as SA from TEST1.

And of course, the developer can't run it either.

And it works fine in the production server.

I'm thinking the basics are there but something isn't right in some permission somewhere.

View 9 Replies View Related

Transact SQL :: Read Unicode Character Using OPENROWSET

Jun 27, 2012

I am reading text file using OPENROWSET command. The read is successful. But the UNICODE characters in the file is not showing properly in the output.I am using a sql like below:

select
*
FROM
OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','Text;Database=ppa20-igloo-fsMODELSTORECR106_GIM_UKGISourceFilesProcess;HDR=Yes;Format=Delimited(|)',
'SELECT * FROM [RUW_P_Reinsurers_Aviva_and_Others_Map.txt]')

how should I read the unicode characters correctly.

View 8 Replies View Related

Read Text File From SQL Server, Read Its Content, And Load It In RichTextBox (Related Component: Context.Response.BinaryWrite(), And StreamReader)

Nov 26, 2007

OBJECTIVE: I would like to read a text file from SQL Server 2000, read the text file content, and load its conntents in a RichTextBoxTHINGS I'VE DONE AND HAVE WORKING:1) I've successfully load a text file (ex: textFile.txt) in sql server database table column (with datatype Image) 2) I've also able to load the file using a Handler as below: using System;using System.Web;using System.Data.SqlClient;public class HandlerImage : IHttpHandler {string connectionString;public void ProcessRequest (HttpContext context) {connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["NWS_ScheduleSQL2000"].ConnectionString;int ImageID = Convert.ToInt32(context.Request.QueryString["id"]);SqlConnection myConnection = new SqlConnection(connectionString);string Command = "SELECT [Image], Image_Type FROM Images WHERE Image_Id=@Image_Id";SqlCommand cmd = new SqlCommand(Command, myConnection);cmd.Parameters.Add("@Image_Id", System.Data.SqlDbType.Int).Value = ImageID;SqlDataReader dr;myConnection.Open(); cmd.Prepare(); dr = cmd.ExecuteReader();if (dr.Read()){ //WRITE IMAGE TO THE BROWSERcontext.Response.ContentType = dr["Image_Type"].ToString();context.Response.BinaryWrite((byte[])dr["Image"]);}myConnection.Close();}public bool IsReusable {get {return false;}}}'>'>
<a href='<%# "HandlerDocument.ashx?id=" + Eval("Doc_ID") %>'>File
</a>- Click on this link, I'll be able to download or view the file WHAT I WANT TO DO, BUT HAVE PROBLEM:- I would like to be able to read CONTENT of this file and load it in a string as belowStreamReader SR = new StreamReader()SR = File.Open("File.txt");String contentText = SR.Readline();txtBox.text = contentText;BUT THIS ONLY WORK FOR files in the server.I would like to be able to read FILE CONTENTS from SQL Server.PLEASE HELP. I really appreciate it.

View 1 Replies View Related

OpenRowset On A DBase IV File

May 26, 2000

Has anyone had any experience using the openrowset function to access a dbase IV file? I can access the file using ADO from within VB but not getting anywhere using openrowset. If anyone knows the syntax or has an example it would be greatly appreciated.

Thanks in advance...

Jim

View 4 Replies View Related

Openrowset To Text File

Mar 29, 2002

Can I use OPENROWSET in Query Analyzer to connect to a text file in a SELECT statement and/or an INSERT statement? I need to move data from a text file to a SQL Server db. But, I can't figure out the right parameters for the OPENROWSET method. Thanks for any help.

Gerald

View 1 Replies View Related

OPENROWSET On XML File Through HTTP

May 7, 2008

Hi everyone,


I am currently using the OPENROWSET command to read a XML file.


-- Use OPENROWSET to read an XML file from the file system

SELECT @xml = BulkColumn

FROM OPENROWSET(BULK 'c:file.xml', SINGLE_BLOB) TempXML


However, the file I wish to process is being generated externally and published through a web server. The file is constantly being updated, and I need to have the latest data frequently. Is it possible to do something along the lines of:


-- Use OPENROWSET to read an XML file from the file system
SELECT @xml = BulkColumn

FROM OPENROWSET(BULK 'http://webserver/file.xml', SINGLE_BLOB) TempXML


If it is not possible, can someone recommend the best method to copy/download the file? I have considered standalone Windows Services and utilizing SQL Server. Are there significant pros or cons to either approach? Are there other methods I am not awere of? Any feedback on this would be greatly appreciated.


Thanks,


Matt K.

View 3 Replies View Related

From Sql Column To File, OPENROWSET?

Aug 28, 2006

Hi There

I am using OPENROWSET to import a file from disk to a varbinary(max) column in sql server.

However as far as i can see OPENROWSET is only to import into Sql Server. However i need to reverse this as well, by that i mean export a varbinary(max) column data to a file on disk. How can i do this ? (The file is a compress text file).

How does this work for file types, i mean you can import any file as binary but when you export it back to disk will the file typr still work, will a .xls or a.exe imprted and exported like this still function 100%.

Thanx?

View 9 Replies View Related

How To Query An Excel File By Using Openrowset

Mar 1, 2007

Hi everyone,

I'm trying to query an excel file and I get a mistake. The query is as follows:

SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:ExcelFile.xls', 'select * from Sheet1')

and I get the following error message:

Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error.
[OLE/DB provider returned message: The Microsoft Jet database engine could not find the object 'Book1'. Make sure the object exists and that you spell its name and the path name correctly.]
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IColumnsInfo::GetColumnsInfo returned 0x80004005: ].

I'm thanking any help that you can give.

Thanks,

Oscar.

View 7 Replies View Related

OPENROWSET Format File Dynamic

May 22, 2008

Hi,

Can someone please point me as to where I can find info for the following. I have seen this somewhere but I am unable to find it.

I am trying to do
INSERT INTO Table
SELECT ...
FROM OPENROWSET(BULK '\sharedDriveDataFile.txt',
FORMATFILE = '\sharedDriveFormatFile.txt',
FIRSTROW = 2)
AS Q

How can I make that shared drive dynamic? as such..hoping not to use dynaic SQL
INSERT INTO Table
SELECT ...
FROM OPENROWSET(BULK @SharedDrive DataFile.txt',
FORMATFILE = @SharedDrive FormatFile.txt',
FIRSTROW = 2)
AS Q

View 1 Replies View Related

Can Not Access Excel File Using OpenRowset

Aug 8, 2007



I am using SQLServer 2005 SP2. I enabled the Ad Hoc Distributed Queries and DisallowAdhocAccess registry option is explicitly set to 0. Query is working fine when I remote desk to the server and execute when I run same query from my workstation I am getting following error


Msg 7399, Level 16, State 1, Line 1

The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider did not give any information about the error.

Msg 7303, Level 16, State 1, Line 1

Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".


Any help is appreciated.
Thanks
--
Farhan

View 8 Replies View Related

OPENROWSET ( CAN WE CREATE FILE WITHOUT EXCEL TEMPLATE??)

Mar 20, 2008

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D: esting.xls;', 'SELECT * FROM [SheetName$]') select * from pubs.dbo.authors
 
I am using similiar query to above to create a excel file, however for this to work, I need to create a template file which has the same columns as the authors table. Is there a way to NOT to define template columns , as I some times will not know which columns will be available... as teh query is dynamic....

View 4 Replies View Related

Openrowset(bulk '\server1c$file.txt') Fails!

Aug 3, 2007

select * from openrowset(bulk '\server1c$file.txt', SINGLE_BLOB) as t
works from sql server itself, but doesn't work from any other machine. I got
"Operating system error code 5(Access is denied.)."
I am running as the domain admin, the file.txt has full control for everyone. In server1 even log, I see Anonymous Logon.


Please help!

Thanks,

Bo

View 3 Replies View Related

Import Excel-File (OPENROWSET) On X64 SQL Server

Jan 7, 2008

Hi, recently I encountered the following problem:
I tried to execute a stored procedure on the newly installed SQL 2005 Server (now on x64 Win Server 2003) which imports an Excel-File into a DB table.
We use OPENROWSET to access the Excel data. But I recognized this is dependent on Jet OLE DB which seems is not available for x64 windows.

Is there another way to import excel data using a stored procedure.

thank you in advance, rene

View 12 Replies View Related

OPENROWSET, Querying External Text File

May 8, 2006

Hi,

I have to write a query that queries a database table and a text file wich is delimited using fixed width values. I have seen some examples using access or another databse but not much about a text file. Is this the best way? Idon't want to set up a linked server. I want everything to be within the query.

My understanding is that I should be able to do it since a text file can be a valed OLE DB datasource, but I am having trouble finding example syntax. Can all my connection info be passed with the OPENROWSET function? Can I do it by just writing a query? Or do I have to set up and configure other things?

Any guidence, tips, advice, examples, or links of syntax appreciated.

Mike

View 1 Replies View Related

SQL Server 2012 :: Loading Image From File System Into Query Using Openrowset

May 14, 2014

I have a directory with images and a table in my DB with the path of each file. The main application allow me to create reports where I can display an image, so I was thinking to use a query like:

SELECT [ID]
,[PT_CODE]
,[FILE_PATH],
CASE WHEN [FILE_PATH] IS NOT NULL THEN
(SELECT * FROM OPENROWSET(BULK [FILE_PATH], SINGLE_BLOB) TT)
END
AS IMAGE_LOADED
FROM [DB].[dbo].[TABLE_MR_FILES]But I keep getting the error:

Incorrect syntax near 'FILE_PATH'.I have try multiple combinations without luck to make the OPENROWSET read the path stored in the column [FILE_PATH]. What am I missing?

Note: I am using MSSQL 2012. I don't want to import the images into the DB just load them in the fly as needed by the report runned from the application. I have full access to the DB so if a store procedure is the solution I can go with it.

View 4 Replies View Related

Any Idea Why OpenRowSet To Open Excel File Doesn't Work Well In SQL 2005?

Mar 3, 2007

Maybe it worked once, but in most time it doesn't work, query like below

select top 10 *
from OpenRowSet('microsoft.jet.oledb.4.0','Excel 8.0;hdr=yes;database=\ws8webablefilessitefiles4000010
eibcactive.xls',
'select * from [crap2$]')


I got error

OLE DB provider "microsoft.jet.oledb.4.0" for linked server "(null)" returned message "Unspecified error".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "microsoft.jet.oledb.4.0" for linked server "(null)".


but the same query can run without any problem on a SQL 2000 server run on a server in the same network.

Any idea?

View 12 Replies View Related

Read Text File From Flat File Connection Manager SSIS

May 13, 2008

Hello Experts,
I am createing one task (user control) in SSIS. I have property grid in my GUI and 2 buttons (OK & Cancle).
PropertyGrid has Properties like SourceConnection, OutputConnection etc....right now I am able to populate Connections in list box next to Source and Output Property.

Now my question to you guys is depending on Source Connection it should read that text file associated with connection manager. After validation it should pick header (first line of text file bases on record type) and write it into new file when task is executed. I have following code for your reference. Please let me know I am going in right direction or not..
What should go here ?
->Under Class A

public override DTSExecResult Execute(Connections connections, VariableDispenser variableDispenser, IDTSComponentEvents componentEvents, IDTSLogging log, object transaction)

{

//Some code to read file and write it into new file

return DTSExecResult.Success;

}


public const string Property_Task = "CustomErrorControl";

public const string Property_SourceConnection = "SourceConnection";



public void LoadFromXML(XmlElement node, IDTSInfoEvents infoEvents)

{

if (node.Name != Property_Task)

{

throw new Exception(String.Format("Invalid task element '{0}' in LoadFromXML.", node.Name));

}

else

{

try

{



_sourceConnectionId = node.Attributes.GetNamedItem(Property_SourceConnection).Value;



}

catch (Exception ex)

{

infoEvents.FireError(0, "LoadFromXML", ex.Message, "", 0);

}

}

}

public void SaveToXML(XmlDocument doc, IDTSInfoEvents infoEvents)

{

try

{

// // Create Task Element

XmlElement taskElement = doc.CreateElement("", Property_Task, "");

doc.AppendChild(taskElement);

// // Save source FileConnection

XmlAttribute sourcefileAttribute = doc.CreateAttribute(Property_SourceConnection);

sourcefileAttribute.Value = _sourceConnectionId;

taskElement.Attributes.Append(sourcefileAttribute);

}

catch (Exception ex)

{

infoEvents.FireError(0, "SaveXML", ex.Message, "", 0);

}

}

In UI Class there is OK Click event.

private void btnOK_Click(object sender, EventArgs e)

{

try

{



_taskHost.Properties[CustomErrorControl.Property_SourceConnection].SetValue(_taskHost, propertyGrid1.Text);

btnOK.DialogResult = DialogResult.OK;

}

catch (Exception ex)

{

Console.WriteLine(ex);

}

#endregion

}

View 10 Replies View Related

SQL 2012 :: How To Do Selective Read Of File Stored In File Table

Jul 2, 2015

I have a filetable that contains a binary file. I need to do a selective read of the file stored in the file table. I can write a C# CLR function that will open the file, read n bytes the from a starting byte. Or I can write a SQL statement that reads the stream in the filetable into a VARBINARY variable using SUBSTRING beginning at the starting byte (offset from 1) for the same n bytes.

Both give me the same result. However, the SQL statement takes considerably longer to read. I know there is overhead in reading through SQL (interpreted language), but the difference in performance is substantial, and I can only attribute this performance degradation if SQL first tries to "load" the entire stream before it identifies the portion of the stream that it needs to read beginning at the starting byte offset.

I wonder if this is the case or if there is another option to read a stream from a filetable directly through SQL queries that is more efficient.

View 3 Replies View Related

How Read File CSV File In Remote Server Using Bulk

Mar 24, 2008

Hi All,

I need to read a csv file, which is in remote server using SQl Bulk Insert Command.

Can I read a file Which is in remote server using BULK INSERT.

Thank you.......

View 1 Replies View Related

Read XML File From File System?

Jan 8, 2002

Anyone reading XML disk-files into SQL Server?

I have a process that I may want to do this with.

It would be a stored procedure that would read the XML attributes into 2 tables, the number of attributes could be 1-N, so I thought XML would be a good choice. Also, one of the attributes could be up to 4000 characters. I think this may limit our options, can 100-150 4000 character strings be passed in a standard call to a query/proc in SQL?

Currently the client application makes round-trip network calls to save upwards of 100 pairs of data. 1 header row, and many detail rows. All within a transaction.

I think If we move an XML file to the SQL box, then do all the import/save work on the "Server" side it would be much better. Cutting the transaction time down a lot by not doing so many round-trips at network speed...

Thoughts?

View 1 Replies View Related

Read File

Aug 28, 2003

Any one can help me how to read a file(.txt) with in the store procedure?

View 2 Replies View Related

Read From .ini File

Jan 4, 2006

hi,
i have a requirement in which i need to read from a .ini file in the stored procedure of sql server 2K.

is it possible? i tried searching on google but i cannot find anything that can help.

View 1 Replies View Related

Read XMl File

Feb 14, 2007

Can any one tell me how to read the XML file using sql syntax.

I hav also posted my full requirement why I need to read the XML file in Transact_Sql forum list.

View 1 Replies View Related

Cannot Read Some DBF File

Jun 6, 2007

Hi All

I am trying to load DBF files into SQL server within CLR (actually if just running the select statement outside, say within the SQLQuery window, i got the same result), but with the following error:

Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "VFPOLEDB" for linked server "MYDBF" does not contain the table "T8866064". The table either does not exist or the current user does not have permissions on that table.


I created the linked server in this way

EXEC sp_addlinkedserver
@server = 'MYDBF',
@provider = 'VFPOLEDB',
@srvproduct = 'My Data',
@datasrc = 'c:data'

i did not create the login since my SQL instance is running under a superaccount with all privilege.

What frustrates me is that i can read most of the dbf files, but just a few of them is not readable.

Can anyone give me some hints on it?

by the way, i am using vfp9.0

thanks

michael

View 7 Replies View Related

How To Read Binary File

Jun 6, 2007

Need help reading a binary file see below for details...
 
 I have uploaded a csv file into a sql table.
Now i want to extract the data and insert the data in the csv file into another sql table.
 What commands can i use in sql to extract/ read  the data ? 
 
 
 

View 7 Replies View Related

Creating A CSV File But Can't Read It.

Nov 4, 2003

Hi, I wrote a report builder that creates a CSV file but I can't redirect to the file to view it. ERROR Cannot find the Server!. This works fine on the dev machine but deploy it and it does not.

Dim Conn As New SqlConnection(ConfigurationSettings.AppSettings("ConStr"))
Dim Cm As SqlCommand
Dim dr As SqlDataReader
Dim FileName As String = Guid.NewGuid.ToString & ".csv"
Dim FilePath As String = Server.MapPath("") & "CSVFiles" & FileName

Dim fs As FileStream = New FileStream(FilePath, FileMode.Create, FileAccess.Write)
Dim sw As StreamWriter = New StreamWriter(fs)
Dim Line As String
Dim lItem As System.Xml.XmlElement
Dim i As Int16
If ValidatePage() Then
Cm = New SqlCommand(BuildQuery, Conn)
Conn.Open()
dr = Cm.ExecuteReader()

Dim lXmlDoc As New System.Xml.XmlDocument()
lXmlDoc.LoadXml(txtHXml.InnerText)

For Each lItem In lXmlDoc.DocumentElement.SelectSingleNode("SELECT").ChildNodes
Select Case lItem.InnerText
Case "chkPRId"
Line &= "PR Id,"
Case "chkDateIssued"
Line &= "Date Issued,"
Case "chkOriginator"
Line &= "Originator,"
Case "chkBuyer"
Line &= "Buyer,"
Case "chkVendor"
Line &= "Vendor,"
Case "chkCostCode"
Line &= "Cost Code,"
Case "chkOracleRef"
Line &= "Oracle Reference,"
Case "chkTotal"
Line &= "Total,"
End Select
Next
Line = Line.Substring(0, Line.Length - 1)
sw.WriteLine(Line)

Line = ""
While dr.Read
For i = 0 To dr.FieldCount - 1
Line = Line & dr(i) & ","
Next
sw.WriteLine(Line)
Line = ""
End While

dr.Close()
Conn.Close()
sw.Close()
fs.Close()
Response.Redirect(FilePath)
End If
ResetPage()
PopulateListBoxFromXML()

View 1 Replies View Related

Read DataBase File

Jan 17, 2002

Hi,
I received a SQL Server 6.5 database (.dat and .Log files). I'm currently running 7.0. Is there any way to read/import this data?
I tried to do this:
I have installed SQL Server 6.5. And After install, I have created a database with the same names (.dat an .log) and make it bigger than the first .dat and .log files.
Then, I have stoped the SQL server service, have deleted the .DAT and .LOG files that i have created, and have copied the first .DAT and .LOG in their place. I have Started the SQL server service and the database was beeing suspected. I stil unable to read data.
Can you help me?

View 1 Replies View Related

READ A FILE WITH EXTENSION Dat

Aug 16, 1999

Hi,

I need to read a binary file with extention *.dat like this:
tat.dat and import it in ms sql server 7.0.

Thanks for any help

Dr Bangaly Diané

View 2 Replies View Related

Read Text File By T-SQL

Feb 16, 2008

hi
how can i read a txt file by using T-SQL commands.
thanx

View 12 Replies View Related

How Can I Read One External File (*.txt,*.csv) Through

Dec 14, 2001

How can I read one external file (*.txt,*.csv) through
stored procedure in MS Sql Server 2000 ?

On the database Interbase its very simple :

[CREATE TABLE table [EXTERNAL [FILE] ’ <filespec>’]
( <col_def> [, <col_def> | <tconstraint> …]);
EXTERNAL [FILE]“<filespec>
” Declares that data for the table under creation resides
in a table or file outside the database;
<filespec> is the complete file specification of the
external file or table]


Please advice

Thanks


Patricio

View 1 Replies View Related

Read Data From File Imp Into MS-SQL

Mar 24, 2006

Hi,

Ik like to read data from a file (well formatted) into as MS-SQL database.

What is the best way to do this.

Jim

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved