Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Friday, March 30, 2012

Help opening .MDF file

I'm trying to follow the article

http://aspnet.4guysfromrolla.com/articles/031506-1.aspx. It gives a sample to download at the bottom which I did. I'm trying to take a look at the Stored Proc that were created in the PagingData.mdf. The only thing included in the App_Data folder is PagingData.mdf file. How can I open the DB or attach it to my SQL2005 server? There is no .ldf file included in thesample so the attaching is failing.

You have two possible options connect the MDF to Management Studio and see if you can access everything or Backup and Restore the database SQL Server will receate everything including stored procs and LDF. Hope this helps.

http://blogs.msdn.com/sqlexpress/archive/2006/11/22/connecting-to-sql-express-user-instances-in-management-studio.aspx

|||

You can attach the MDF file to the SQL Server 2005 by using the simple command

SP_ATTACH_DB <Give your DB Name, any name is fine>,<Location of the DB file>

and programatically you can connect to the MDF file using code as described in

http://ambarishganguly.blogspot.com/2006/10/sql-server-express-xcopy.html

Hope this helps.

Thanks

Ambarish

sql

Monday, March 26, 2012

Help on print report or export to a file

Hi,
I'm new to SQL programming. I'm using MS SQL 2000, and I like to schedule a
job to print a report which has information pulling from tables.
For example,
select * from customer where status='yes'
I like to retrieve this list either on a printer or to a file.
Is that possible? If this needs to be coded, can you please give me some
example?
Thanks so much in advance,
SarahHi,
I wanted to add more information to my question. Or how to save the results
of stored procedure to a file to print to a printer.
Thanks,
Sarah
"Sarah" <sguo@.coopervision.com> wrote in message
news:%23bcqFfUFGHA.140@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I'm new to SQL programming. I'm using MS SQL 2000, and I like to schedule
> a job to print a report which has information pulling from tables.
> For example,
> select * from customer where status='yes'
> I like to retrieve this list either on a printer or to a file.
> Is that possible? If this needs to be coded, can you please give me some
> example?
> Thanks so much in advance,
> Sarah
>|||You can use bcp and xp_cmdshell to write the results of a query to a text fi
le.
Here is a link that explains the process.
http://www.sqlteam.com/item.asp?ItemID=4722
Ryan Powers
Clarity Consulting
http://www.claritycon.com
"Sarah" wrote:

> Hi,
> I wanted to add more information to my question. Or how to save the result
s
> of stored procedure to a file to print to a printer.
> Thanks,
> Sarah
> "Sarah" <sguo@.coopervision.com> wrote in message
> news:%23bcqFfUFGHA.140@.TK2MSFTNGP12.phx.gbl...
>
>|||> I like to retrieve this list either on a printer or to a file.
You can send to a file easily... some simple examples here:
http://www.aspfaq.com/2482
Unfortunately, SQL Server has no idea what a printer is. Might be better
suited for an external app (or maybe reporting services?).|||Thanks Aaron and Ryan, that's great help.
Sarah
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uIv9aGVFGHA.2856@.TK2MSFTNGP12.phx.gbl...
> You can send to a file easily... some simple examples here:
> http://www.aspfaq.com/2482
> Unfortunately, SQL Server has no idea what a printer is. Might be better
> suited for an external app (or maybe reporting services?).
>

Help on Installing MSRS using a domain account.

Hi,
I am new to MSRS,Please tell me how to do the below mention things
Can we change the custom.dll to use an account from a config file instead of
the account from the app pool?
Microsoft does not support installing MSRS using a domain account.
MSRS corruption of the domain account has happened more than once in all
environments. The cost to re-install is too high.
Any Ideas?
RegardsThe dll I am referring to is DataProviders.dll.
This has code that needs to axess the dfsroot folder on the file server.
If you add code to this dll to read a config file for the username and
password and use it when opening the xml file on the file server, we would
not need to use a domain account in MSRS. Is this possible?
"gp" <gprabhakaran@.axentis.com> wrote in message
news:OuYFqGSLGHA.208@.tk2msftngp13.phx.gbl...
> Hi,
> I am new to MSRS,Please tell me how to do the below mention things
> Can we change the custom.dll to use an account from a config file instead
> of the account from the app pool?
> Microsoft does not support installing MSRS using a domain account.
> MSRS corruption of the domain account has happened more than once in all
> environments. The cost to re-install is too high.
> Any Ideas?
> Regards
>

Friday, March 23, 2012

Help on INI file

Hi all,
I'm building a DTS package that needs to take parameters from an INI
file. The SQL statement in the Transform task goes something like this:
select * from customer where division in ('D','I','2','3','C')
I need to pass the division 'D','I','2','3','C' part in because there
might be more divisions we need in the future or change of divisions,
we don't want to modifiy the package every time. So I set it in the INI
file like this and read it into a global variable:
[Customer]
Division = 'D','I','2','3','C'
But SQL doesn't recognize the SQL statement "select * from customer
where division in (?), where ? stands for the global variable. I tried
with setting Division = "'D','I','2','3','C'" in INI file, it still
doesn't work. The only way it works is to pass the 5 values as 5
seperate parameters and thus 5 global variables then the SQL statement
is like this:
select * from customer where division in (?,?,?,?,?)
But this defeats the purpose because I can't add another parameter in
the INI file without having to open the package and make changes.
Has anybody run into this before? Any suggestions is appreciated.
Thanks,http://www.sommarskog.se/arrays-in-sql.html

Simon

Help on Ignored Words in Full Text Query

I'm implementing the search features on a web site.
If I search for several words not in the noise file everithing is ok.
If I search with several words and only one of it is in the noise file
the query fails with
Execution of a full-text operation failed. A clause of the query
contained only ignored words.
Why say me that the clause contain only ignored words?
This is the query:
SELECT * FROM MyTable WHERE CONTAINS(*,'"lock" AND "close" AND
"window"')
SELECT * FROM MyTable WHERE CONTAINS(*,'"lock" AND "from" AND
"window"')
Thanks a lot for your help!!
Andrew
"From" is considered to be a noise word and can trigger this error. The best
approach for smaller tables you are Full Text Indexing is to empty the
contents your noise word list and replace it with a single space.
To do this go to a command prompt and type net stop MSSearch and press enter
Go to go to c:\Program Files\Microsoft
SQLServer\mssql\ftdata\sqlserver\config. Then edit the noise.enu (for US
English) in notepad, press ctrl and A, and then press the space bar. Then
select File and Save.
Then restart MSSearch.
You should then do a full population.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
"Andrew" <a.fileccia@.contactaspa.com> wrote in message
news:53107877.0412040626.80f78c3@.posting.google.co m...
> I'm implementing the search features on a web site.
> If I search for several words not in the noise file everithing is ok.
> If I search with several words and only one of it is in the noise file
> the query fails with
> Execution of a full-text operation failed. A clause of the query
> contained only ignored words.
> Why say me that the clause contain only ignored words?
> This is the query:
>
> SELECT * FROM MyTable WHERE CONTAINS(*,'"lock" AND "close" AND
> "window"')
> SELECT * FROM MyTable WHERE CONTAINS(*,'"lock" AND "from" AND
> "window"')
> Thanks a lot for your help!!
> Andrew
|||Andrew,
This is a common question on this newsgroup and one that can be workaround,
via either client-side or server-side solutions. As for the text of the
message, I agree that it is badly written as most often the query will not
contain only noise words, but in fact one or more depending upon how the
search words are specified in the search condition.
I'd recommend that you review SQL Server 2000 BOL title "Full-text Search
Recommendations", and KB article 246800 (Q246800) "INF: Correctly Parsing
Quotation Marks in FTS Queries" at
http://support.microsoft.com//defaul...b;EN-US;246800 (with T-SQL,
JavaScript, & VBScript coding examples) and search this newsgroup for
SearchPage.htm (or SearchPage.zip) for server-side and client-side solution
of removing the noise words before issuing a SQL FTS query.
Hope this helps!
John
"Andrew" <a.fileccia@.contactaspa.com> wrote in message
news:53107877.0412040626.80f78c3@.posting.google.co m...
> I'm implementing the search features on a web site.
> If I search for several words not in the noise file everithing is ok.
> If I search with several words and only one of it is in the noise file
> the query fails with
> Execution of a full-text operation failed. A clause of the query
> contained only ignored words.
> Why say me that the clause contain only ignored words?
> This is the query:
>
> SELECT * FROM MyTable WHERE CONTAINS(*,'"lock" AND "close" AND
> "window"')
> SELECT * FROM MyTable WHERE CONTAINS(*,'"lock" AND "from" AND
> "window"')
> Thanks a lot for your help!!
> Andrew
sql

Help on DB design

Hi,
I have a form where users can choose number of file uploads ( drop down ) and upload images. I need to store the path of images in database.I want to know what is the best way to store multiple file upload paths. As per my knowledge it possible to store paths in one field with delimiter. Is there any other good way to store the paths.

Raj

It depends,

You have 3 (or more) options,

Store as Individual Table(rows

Each file will be stored as single row with key field.

The master table can hold the key field & number of files

Store as Delimited Value

If you use SQL server 2000, you are not allowed to store more than 8000 chars, otherwise you have to change the data type to LOB(text). In SQL Server 2005 you can use the Varchar(max).

Manipulations need to be done on the UI.

Single row modification can’t be done on the UI, you have to stick with your UI.

Store as XML value

If you use SQL Server 2005, you can use new data type XML.

You can store at any number of chars

Easy to manipulate on Database itself.

Structured & Well Managed

My Rank is – 1.XML, 2.Table(rows), 3.Delimited value

|||^Thank you Manivannan.D.Sekaran . I will follow Table(rows) as i am using sql server 2000.

Help on DB Design

Hi,
I have a form where users can choose number of file uploads ( drop down ) and upload images. I need to store the path of images in database.I want to know what is the best way to store multiple file upload paths. As per my knowledge it possible to store paths in one field with delimiter. Is there any other good way to store the paths.

Raj

Quote:

Originally Posted by bootzwiz

Hi,
I have a form where users can choose number of file uploads ( drop down ) and upload images. I need to store the path of images in database.I want to know what is the best way to store multiple file upload paths. As per my knowledge it possible to store paths in one field with delimiter. Is there any other good way to store the paths.

Raj


Generate FileId in the database and GroupId and FilePath

FileId FileGroupID FilePath
--------------------------------

Like this|||

Quote:

Originally Posted by bootzwiz

Hi,
I have a form where users can choose number of file uploads ( drop down ) and upload images. I need to store the path of images in database.I want to know what is the best way to store multiple file upload paths. As per my knowledge it possible to store paths in one field with delimiter. Is there any other good way to store the paths.

Raj


i offer to have the following entity/table for your application :

1-an entity named "Session " with these fields (SessionID,SessionName,SessionDate ) with SessionID for primary key.

2-an entity named SessionFiles with these fields(SessionID,FilenameWithPath,uploadStatus) with "SessionID,FilenameWithPath" for primary key.

3-make relation for these two table with SessionID field.

4-each form shows one session in your application for uploading the related SessionFiles.

5-Enjoy it.sql

Monday, March 19, 2012

Help needed with this Error message while running a DTS package

Hi

I am trying to import a excel file into a table but when i run it i am getting this error and i am not sure what this eror is

- Copying to [ICCStatements].[dbo].[Sheet1$] (Error)

Messages

Error 0xc0202009: Data Flow Task: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Unspecified error".
(SQL Server Import and Export Wizard)

Error 0xc020901c: Data Flow Task: There was an error with input column "AdminShowInKit" (148) on input "Destination Input" (102). The column status returned was: "The value violated the integrity constraints for the column.".
(SQL Server Import and Export Wizard)

Error 0xc0209029: Data Flow Task: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "input "Destination Input" (102)" failed because error code 0xC020907D occurred, and the error row disposition on "input "Destination Input" (102)" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc0047022: Data Flow Task: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination - Sheet1$" (89) failed with error code 0xC0209029. The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)

Error 0xc0047021: Data Flow Task: SSIS Error Code DTS_E_THREADFAILED. Thread "WorkThread0" has exited with error code 0xC0209029. There may be error messages posted before this with more information on why the thread has exited.
(SQL Server Import and Export Wizard)

Any help will be appreciated.. RegardsKArenThe key error is this:

Error 0xc020901c: Data Flow Task: There was an error with input column "AdminShowInKit" (148) on input "Destination Input" (102). The column status returned was: "The value violated the integrity constraints for the column.".
(SQL Server Import and Export Wizard)

There seems to be an error in the AdminShowInKit column. Possibly a missing value.

Help needed with importing XML

SQL server 2005
ive been trying very unsucessfully to try and import an xml file into a
SQL2005 table. I have a schema but am unsure as what to do next. I have bee
n
looking at lots od different exmples but its way over my head. i need a ste
p
by step example that will import the following xml file into two tables
<?xml version="1.0" encoding="ISO-8859-1"?>
<BACSDocument>
<Data>
<ARUCS>
<Header reportType="REFT1027" adviceNumber="01077"
currentProcessingDate="2005-12-05"></Header>
<AddresseeInformation name="Mr Bean "
address1="Company Name " address2="This Place "
address3="This Town " address4="This County
" address5="A12 45T "></AddresseeInformation>
</ARUCS>
</Data>
<SignatureMethod></SignatureMethod>
<Signature></Signature>
</BACSDocument>
table 1 will contain all the header information in fields , reportType,
advicenumber etc as all the address info into table 2.
Once i have created the tables, is there a way to just do the import direct
in TSQL
any help will be very welcome as im struggling to grasp thisHi Peter,
I've made up an really simple table definition for table1 and table2 and
left some of the columns out to cut down on size. You want to decompose the
XML into relational name-value pairs and do an insert of pieces into two
separate tables. This is *assuming* you don't have more than one Header or
AddresseeInformation in the document, or more than one document in the XML.
Example follows mail message.
First way is the easiest. Use the xml.value method to extract each value,
given the attribute name in the document, 1 column per column in the rowset
(table) you want. This may be able to be optimized by changing the query,
but I'm trying to keep it simple for exposition.
Second way is to use xml.nodes method to obtain a rowset of name-value
pairs. Then use the PIVOT operator to pivot the values into one row and
multiple column values. I've done it in two steps (#temp table) to
illustrate what nodes returns, then combined it into one step.
You could also use OpenXML to do this, but it might require more storage
overhead.
Hope this helps,
Cheers,
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
CREATE TABLE table1 (
reporttype varchar(100),
adviceNumber varchar(100),
currentProcessingDate datetime
)
go
CREATE TABLE table2 (
name varchar(100),
address1 varchar(100),
address2 varchar(100)
)
go
declare @.x xml
set @.x =
'<?xml version="1.0" encoding="ISO-8859-1"?>
<BACSDocument>
<Data>
<ARUCS>
<Header reportType="REFT1027" adviceNumber="01077"
currentProcessingDate="2005-12-05"></Header>
<AddresseeInformation name="Mr Bean "
address1="Company Name " address2="This Place "
address3="This Town " address4="This County
" address5="A12 45T "></AddresseeInformation>
</ARUCS>
</Data>
<SignatureMethod></SignatureMethod>
<Signature></Signature>
</BACSDocument>
'
/* First way, using xml.value
INSERT table1
select @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.reportType',
'varchar(100)') as a,
@.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.adviceNumber',
'varchar(100)') as b,
@.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.currentProcessingDate',
'datetime') as c
SELECT * FROM table1
-- now do the same for table2
INSERT table2
select @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.name',
'varchar(100)') as a,
@.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.address1',
'varchar(100)') as b,
@.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.address2',
'varchar(100)') as c
SELECT * FROM table2
*/
/* Second way, using xml.nodes, intermediate table for exposition
select t.c.value('local-name(.)', 'varchar(50)') as Name,
t.c.value('data(.)', 'varchar(100)') as Value
into #temp
from @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
select * from #temp
SELECT [reportType], [adviceNumber], [currentProcessingDate]
FROM #temp
PIVOT (
MAX([Value]) FOR
[Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
) as p
-- now do the same for table2 (elided)
*/
-- third way, combination of second way into one statement.
insert table1
select [reportType], [adviceNumber], [currentProcessingDate]
from
(
SELECT t.c.value('local-name(.)', 'varchar(50)') as [Name],
t.c.value('data(.)', 'varchar(100)') as [Value]
FROM @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
) AS namevalue
PIVOT (
MAX([Value]) FOR
[Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
) as p
-- now do the same for table2 (elided)
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:E8722036-4DD5-4F15-A4FB-6CF9BF9044EF@.microsoft.com...
> SQL server 2005
> ive been trying very unsucessfully to try and import an xml file into a
> SQL2005 table. I have a schema but am unsure as what to do next. I have
> been
> looking at lots od different exmples but its way over my head. i need a
> step
> by step example that will import the following xml file into two tables
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <BACSDocument>
> <Data>
> <ARUCS>
> <Header reportType="REFT1027" adviceNumber="01077"
> currentProcessingDate="2005-12-05"></Header>
> <AddresseeInformation name="Mr Bean "
> address1="Company Name " address2="This Place
> "
> address3="This Town " address4="This County
> " address5="A12 45T "></AddresseeInformation>
> </ARUCS>
> </Data>
> <SignatureMethod></SignatureMethod>
> <Signature></Signature>
> </BACSDocument>
> table 1 will contain all the header information in fields , reportType,
> advicenumber etc as all the address info into table 2.
> Once i have created the tables, is there a way to just do the import
> direct
> in TSQL
> any help will be very welcome as im struggling to grasp this|||Bob,
Thank you very much, that has showed me a lot and i have managed to adapt it
to the nomal xml files that im currently recieving, however, and theres
always a however, some of the files have more than one element of the ssame
name, so in the file i have shown earlier, how would i handle it if say it
had three AddresseeInformation for example
thansk in advance
"Bob Beauchemin" wrote:

> Hi Peter,
> I've made up an really simple table definition for table1 and table2 and
> left some of the columns out to cut down on size. You want to decompose th
e
> XML into relational name-value pairs and do an insert of pieces into two
> separate tables. This is *assuming* you don't have more than one Header or
> AddresseeInformation in the document, or more than one document in the XML
.
> Example follows mail message.
> First way is the easiest. Use the xml.value method to extract each value,
> given the attribute name in the document, 1 column per column in the rowse
t
> (table) you want. This may be able to be optimized by changing the query,
> but I'm trying to keep it simple for exposition.
> Second way is to use xml.nodes method to obtain a rowset of name-value
> pairs. Then use the PIVOT operator to pivot the values into one row and
> multiple column values. I've done it in two steps (#temp table) to
> illustrate what nodes returns, then combined it into one step.
> You could also use OpenXML to do this, but it might require more storage
> overhead.
> Hope this helps,
> Cheers,
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
> CREATE TABLE table1 (
> reporttype varchar(100),
> adviceNumber varchar(100),
> currentProcessingDate datetime
> )
> go
> CREATE TABLE table2 (
> name varchar(100),
> address1 varchar(100),
> address2 varchar(100)
> )
> go
> declare @.x xml
> set @.x =
> '<?xml version="1.0" encoding="ISO-8859-1"?>
> <BACSDocument>
> <Data>
> <ARUCS>
> <Header reportType="REFT1027" adviceNumber="01077"
> currentProcessingDate="2005-12-05"></Header>
> <AddresseeInformation name="Mr Bean "
> address1="Company Name " address2="This Place
"
> address3="This Town " address4="This County
> " address5="A12 45T "></AddresseeInformation>
> </ARUCS>
> </Data>
> <SignatureMethod></SignatureMethod>
> <Signature></Signature>
> </BACSDocument>
> '
> /* First way, using xml.value
> INSERT table1
> select @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.reportType',
> 'varchar(100)') as a,
> @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.adviceNumber',
> 'varchar(100)') as b,
> @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.currentProcessingDa
te',
> 'datetime') as c
> SELECT * FROM table1
> -- now do the same for table2
> INSERT table2
> select @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.name'
,
> 'varchar(100)') as a,
> @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.addre
ss1',
> 'varchar(100)') as b,
> @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.addre
ss2',
> 'varchar(100)') as c
> SELECT * FROM table2
> */
>
> /* Second way, using xml.nodes, intermediate table for exposition
> select t.c.value('local-name(.)', 'varchar(50)') as Name,
> t.c.value('data(.)', 'varchar(100)') as Value
> into #temp
> from @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
> select * from #temp
> SELECT [reportType], [adviceNumber], [currentProcessingDate]
> FROM #temp
> PIVOT (
> MAX([Value]) FOR
> [Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
> ) as p
> -- now do the same for table2 (elided)
> */
> -- third way, combination of second way into one statement.
> insert table1
> select [reportType], [adviceNumber], [currentProcessingDate]
> from
> (
> SELECT t.c.value('local-name(.)', 'varchar(50)') as [Name],
> t.c.value('data(.)', 'varchar(100)') as [Value]
> FROM @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
> ) AS namevalue
> PIVOT (
> MAX([Value]) FOR
> [Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
> ) as p
> -- now do the same for table2 (elided)
> "Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
> news:E8722036-4DD5-4F15-A4FB-6CF9BF9044EF@.microsoft.com...
>
>|||Hi Peter,
Those examples showed how to decompose arbitrary XML in multiple unrealated
tables. In a relational database you need to have something tying together
table1 and table2 (adviseNumber?, reportType?). There's nothing in the
document to deduce this. Also, relational doesn't allow repeating groups, so
you'd need a discriminator to distinguish between the 3 nodes. You could
either use ordinal (as I used [1] in the first example to indicate the 1st
AddresseeInformation) or use nodes to do it in one step and insert multiple
rows. But there has to be something in the relational schema tying table1
and table2 together.
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:3D443871-A973-4407-96EE-5E44EA309BBF@.microsoft.com...
> Bob,
> Thank you very much, that has showed me a lot and i have managed to adapt
> it
> to the nomal xml files that im currently recieving, however, and theres
> always a however, some of the files have more than one element of the
> ssame
> name, so in the file i have shown earlier, how would i handle it if say
> it
> had three AddresseeInformation for example
> thansk in advance
> "Bob Beauchemin" wrote:
>|||Bob,
Ive spent he entire day chasing ghosts tying to assing a discriminator , its
easy to code when i know how meny there will be but as these reports are
dynamic i need to find a way to change rowcount to equal the ordinal, and
loop till all the rows have been imported
SELECT t.c.value('local-name(.)', 'varchar(50)') AS Name,
t.c.value('data(.)', 'Varchar(100)') as Value, '1' as RowNumber
INTO #ReturnedItem
FROM
@.XMLDOC.nodes('/BACSDocument/Data/ARUCS/Advice/OriginatingAccountRecords/Ori
ginatingAccountRecord/ReturnedCreditItem[1]/@.*') as t(c)
youve been such a great help so far, think one i can resolve this issue i
can carry on on my own
"Bob Beauchemin" wrote:

> Hi Peter,
> Those examples showed how to decompose arbitrary XML in multiple unrealate
d
> tables. In a relational database you need to have something tying together
> table1 and table2 (adviseNumber?, reportType?). There's nothing in the
> document to deduce this. Also, relational doesn't allow repeating groups,
so
> you'd need a discriminator to distinguish between the 3 nodes. You could
> either use ordinal (as I used [1] in the first example to indicate the 1st
> AddresseeInformation) or use nodes to do it in one step and insert multipl
e
> rows. But there has to be something in the relational schema tying table1
> and table2 together.
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
>
> "Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
> news:3D443871-A973-4407-96EE-5E44EA309BBF@.microsoft.com...
>
>|||If I think I'm understanding what you're asking, there's a few ways to do
this. You could add a gratuitous identity column to #temp and use
INSERT...SELECT instead of SELECT INTO. You could loop using a T-SQL
variable until the nodes function returns no nodes, using sql:variable in
the XQuery predicate. You could have also changed the XPath expression to a
FLWOR expression and selected the position, but SQL Server XQuery doesn't
support the "at" portion of "for $x at $y in ..." syntax or the position()
function used outside of the predicate.
Hope this helps,
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:F327D2A5-07D4-4F37-82BA-23B4BEA60226@.microsoft.com...
> Bob,
> Ive spent he entire day chasing ghosts tying to assing a discriminator ,
> its
> easy to code when i know how meny there will be but as these reports are
> dynamic i need to find a way to change rowcount to equal the ordinal, and
> loop till all the rows have been imported
> SELECT t.c.value('local-name(.)', 'varchar(50)') AS Name,
> t.c.value('data(.)', 'Varchar(100)') as Value, '1' as RowNumber
> INTO #ReturnedItem
> FROM
> @.XMLDOC.nodes('/BACSDocument/Data/ARUCS/Advice/OriginatingAccountRecords/O
riginatingAccountRecord/ReturnedCreditItem[1]/@.*')
> as t(c)
>
> youve been such a great help so far, think one i can resolve this issue i
> can carry on on my own
> "Bob Beauchemin" wrote:
>|||Bob,
Thanks again for the pointers yhoi have to admit ive spend a few hours and
srtill carnt grasp it. I understand what you were saying about the
relationship between table 1 and table 2, that i think i can work out, what
im still struggling with is returning the pivot table for the three addresss
( only for example ). I still can not get the identity colum in using your
previous eamaples. sorry to be a pain but can you pint me in the direction
of an example based of what you have already explained
thanks again for all your help
"Bob Beauchemin" wrote:

> If I think I'm understanding what you're asking, there's a few ways to do
> this. You could add a gratuitous identity column to #temp and use
> INSERT...SELECT instead of SELECT INTO. You could loop using a T-SQL
> variable until the nodes function returns no nodes, using sql:variable in
> the XQuery predicate. You could have also changed the XPath expression to
a
> FLWOR expression and selected the position, but SQL Server XQuery doesn't
> support the "at" portion of "for $x at $y in ..." syntax or the position(
)
> function used outside of the predicate.
> Hope this helps,
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
> "Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
> news:F327D2A5-07D4-4F37-82BA-23B4BEA60226@.microsoft.com...
>
>

Help needed with importing XML

SQL server 2005
ive been trying very unsucessfully to try and import an xml file into a
SQL2005 table. I have a schema but am unsure as what to do next. I have been
looking at lots od different exmples but its way over my head. i need a step
by step example that will import the following xml file into two tables
<?xml version="1.0" encoding="ISO-8859-1"?>
<BACSDocument>
<Data>
<ARUCS>
<Header reportType="REFT1027" adviceNumber="01077"
currentProcessingDate="2005-12-05"></Header>
<AddresseeInformation name="Mr Bean "
address1="Company Name " address2="This Place "
address3="This Town " address4="This County
" address5="A12 45T "></AddresseeInformation>
</ARUCS>
</Data>
<SignatureMethod></SignatureMethod>
<Signature></Signature>
</BACSDocument>
table 1 will contain all the header information in fields , reportType,
advicenumber etc as all the address info into table 2.
Once i have created the tables, is there a way to just do the import direct
in TSQL
any help will be very welcome as im struggling to grasp this
Hi Peter,
I've made up an really simple table definition for table1 and table2 and
left some of the columns out to cut down on size. You want to decompose the
XML into relational name-value pairs and do an insert of pieces into two
separate tables. This is *assuming* you don't have more than one Header or
AddresseeInformation in the document, or more than one document in the XML.
Example follows mail message.
First way is the easiest. Use the xml.value method to extract each value,
given the attribute name in the document, 1 column per column in the rowset
(table) you want. This may be able to be optimized by changing the query,
but I'm trying to keep it simple for exposition.
Second way is to use xml.nodes method to obtain a rowset of name-value
pairs. Then use the PIVOT operator to pivot the values into one row and
multiple column values. I've done it in two steps (#temp table) to
illustrate what nodes returns, then combined it into one step.
You could also use OpenXML to do this, but it might require more storage
overhead.
Hope this helps,
Cheers,
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
CREATE TABLE table1 (
reporttype varchar(100),
adviceNumber varchar(100),
currentProcessingDate datetime
)
go
CREATE TABLE table2 (
name varchar(100),
address1 varchar(100),
address2 varchar(100)
)
go
declare @.x xml
set @.x =
'<?xml version="1.0" encoding="ISO-8859-1"?>
<BACSDocument>
<Data>
<ARUCS>
<Header reportType="REFT1027" adviceNumber="01077"
currentProcessingDate="2005-12-05"></Header>
<AddresseeInformation name="Mr Bean "
address1="Company Name " address2="This Place "
address3="This Town " address4="This County
" address5="A12 45T "></AddresseeInformation>
</ARUCS>
</Data>
<SignatureMethod></SignatureMethod>
<Signature></Signature>
</BACSDocument>
'
/* First way, using xml.value
INSERT table1
select @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.reportType',
'varchar(100)') as a,
@.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.adviceNumber',
'varchar(100)') as b,
@.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.currentProcessingDate',
'datetime') as c
SELECT * FROM table1
-- now do the same for table2
INSERT table2
select @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.name',
'varchar(100)') as a,
@.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.address1',
'varchar(100)') as b,
@.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.address2',
'varchar(100)') as c
SELECT * FROM table2
*/
/* Second way, using xml.nodes, intermediate table for exposition
select t.c.value('local-name(.)', 'varchar(50)') as Name,
t.c.value('data(.)', 'varchar(100)') as Value
into #temp
from @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
select * from #temp
SELECT [reportType], [adviceNumber], [currentProcessingDate]
FROM #temp
PIVOT (
MAX([Value]) FOR
[Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
) as p
-- now do the same for table2 (elided)
*/
-- third way, combination of second way into one statement.
insert table1
select [reportType], [adviceNumber], [currentProcessingDate]
from
(
SELECT t.c.value('local-name(.)', 'varchar(50)') as [Name],
t.c.value('data(.)', 'varchar(100)') as [Value]
FROM @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
) AS namevalue
PIVOT (
MAX([Value]) FOR
[Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
) as p
-- now do the same for table2 (elided)
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:E8722036-4DD5-4F15-A4FB-6CF9BF9044EF@.microsoft.com...
> SQL server 2005
> ive been trying very unsucessfully to try and import an xml file into a
> SQL2005 table. I have a schema but am unsure as what to do next. I have
> been
> looking at lots od different exmples but its way over my head. i need a
> step
> by step example that will import the following xml file into two tables
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <BACSDocument>
> <Data>
> <ARUCS>
> <Header reportType="REFT1027" adviceNumber="01077"
> currentProcessingDate="2005-12-05"></Header>
> <AddresseeInformation name="Mr Bean "
> address1="Company Name " address2="This Place
> "
> address3="This Town " address4="This County
> " address5="A12 45T "></AddresseeInformation>
> </ARUCS>
> </Data>
> <SignatureMethod></SignatureMethod>
> <Signature></Signature>
> </BACSDocument>
> table 1 will contain all the header information in fields , reportType,
> advicenumber etc as all the address info into table 2.
> Once i have created the tables, is there a way to just do the import
> direct
> in TSQL
> any help will be very welcome as im struggling to grasp this
|||Bob,
Thank you very much, that has showed me a lot and i have managed to adapt it
to the nomal xml files that im currently recieving, however, and theres
always a however, some of the files have more than one element of the ssame
name, so in the file i have shown earlier, how would i handle it if say it
had three AddresseeInformation for example
thansk in advance
"Bob Beauchemin" wrote:

> Hi Peter,
> I've made up an really simple table definition for table1 and table2 and
> left some of the columns out to cut down on size. You want to decompose the
> XML into relational name-value pairs and do an insert of pieces into two
> separate tables. This is *assuming* you don't have more than one Header or
> AddresseeInformation in the document, or more than one document in the XML.
> Example follows mail message.
> First way is the easiest. Use the xml.value method to extract each value,
> given the attribute name in the document, 1 column per column in the rowset
> (table) you want. This may be able to be optimized by changing the query,
> but I'm trying to keep it simple for exposition.
> Second way is to use xml.nodes method to obtain a rowset of name-value
> pairs. Then use the PIVOT operator to pivot the values into one row and
> multiple column values. I've done it in two steps (#temp table) to
> illustrate what nodes returns, then combined it into one step.
> You could also use OpenXML to do this, but it might require more storage
> overhead.
> Hope this helps,
> Cheers,
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
> CREATE TABLE table1 (
> reporttype varchar(100),
> adviceNumber varchar(100),
> currentProcessingDate datetime
> )
> go
> CREATE TABLE table2 (
> name varchar(100),
> address1 varchar(100),
> address2 varchar(100)
> )
> go
> declare @.x xml
> set @.x =
> '<?xml version="1.0" encoding="ISO-8859-1"?>
> <BACSDocument>
> <Data>
> <ARUCS>
> <Header reportType="REFT1027" adviceNumber="01077"
> currentProcessingDate="2005-12-05"></Header>
> <AddresseeInformation name="Mr Bean "
> address1="Company Name " address2="This Place "
> address3="This Town " address4="This County
> " address5="A12 45T "></AddresseeInformation>
> </ARUCS>
> </Data>
> <SignatureMethod></SignatureMethod>
> <Signature></Signature>
> </BACSDocument>
> '
> /* First way, using xml.value
> INSERT table1
> select @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.reportType',
> 'varchar(100)') as a,
> @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.adviceNumber',
> 'varchar(100)') as b,
> @.x.value('(/BACSDocument/Data/ARUCS/Header)[1]/@.currentProcessingDate',
> 'datetime') as c
> SELECT * FROM table1
> -- now do the same for table2
> INSERT table2
> select @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.name',
> 'varchar(100)') as a,
> @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.address1',
> 'varchar(100)') as b,
> @.x.value('(/BACSDocument/Data/ARUCS/AddresseeInformation)[1]/@.address2',
> 'varchar(100)') as c
> SELECT * FROM table2
> */
>
> /* Second way, using xml.nodes, intermediate table for exposition
> select t.c.value('local-name(.)', 'varchar(50)') as Name,
> t.c.value('data(.)', 'varchar(100)') as Value
> into #temp
> from @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
> select * from #temp
> SELECT [reportType], [adviceNumber], [currentProcessingDate]
> FROM #temp
> PIVOT (
> MAX([Value]) FOR
> [Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
> ) as p
> -- now do the same for table2 (elided)
> */
> -- third way, combination of second way into one statement.
> insert table1
> select [reportType], [adviceNumber], [currentProcessingDate]
> from
> (
> SELECT t.c.value('local-name(.)', 'varchar(50)') as [Name],
> t.c.value('data(.)', 'varchar(100)') as [Value]
> FROM @.x.nodes('/BACSDocument/Data/ARUCS/Header/@.*') as t(c)
> ) AS namevalue
> PIVOT (
> MAX([Value]) FOR
> [Name] IN ([reportType], [adviceNumber], [currentProcessingDate])
> ) as p
> -- now do the same for table2 (elided)
> "Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
> news:E8722036-4DD5-4F15-A4FB-6CF9BF9044EF@.microsoft.com...
>
>
|||Hi Peter,
Those examples showed how to decompose arbitrary XML in multiple unrealated
tables. In a relational database you need to have something tying together
table1 and table2 (adviseNumber?, reportType?). There's nothing in the
document to deduce this. Also, relational doesn't allow repeating groups, so
you'd need a discriminator to distinguish between the 3 nodes. You could
either use ordinal (as I used [1] in the first example to indicate the 1st
AddresseeInformation) or use nodes to do it in one step and insert multiple
rows. But there has to be something in the relational schema tying table1
and table2 together.
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:3D443871-A973-4407-96EE-5E44EA309BBF@.microsoft.com...[vbcol=seagreen]
> Bob,
> Thank you very much, that has showed me a lot and i have managed to adapt
> it
> to the nomal xml files that im currently recieving, however, and theres
> always a however, some of the files have more than one element of the
> ssame
> name, so in the file i have shown earlier, how would i handle it if say
> it
> had three AddresseeInformation for example
> thansk in advance
> "Bob Beauchemin" wrote:
|||Bob,
Ive spent he entire day chasing ghosts tying to assing a discriminator , its
easy to code when i know how meny there will be but as these reports are
dynamic i need to find a way to change rowcount to equal the ordinal, and
loop till all the rows have been imported
SELECT t.c.value('local-name(.)', 'varchar(50)') AS Name,
t.c.value('data(.)', 'Varchar(100)') as Value, '1' as RowNumber
INTO #ReturnedItem
FROM
@.XMLDOC.nodes('/BACSDocument/Data/ARUCS/Advice/OriginatingAccountRecords/OriginatingAccountRecord/ReturnedCreditItem[1]/@.*') as t(c)
youve been such a great help so far, think one i can resolve this issue i
can carry on on my own
"Bob Beauchemin" wrote:

> Hi Peter,
> Those examples showed how to decompose arbitrary XML in multiple unrealated
> tables. In a relational database you need to have something tying together
> table1 and table2 (adviseNumber?, reportType?). There's nothing in the
> document to deduce this. Also, relational doesn't allow repeating groups, so
> you'd need a discriminator to distinguish between the 3 nodes. You could
> either use ordinal (as I used [1] in the first example to indicate the 1st
> AddresseeInformation) or use nodes to do it in one step and insert multiple
> rows. But there has to be something in the relational schema tying table1
> and table2 together.
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
>
> "Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
> news:3D443871-A973-4407-96EE-5E44EA309BBF@.microsoft.com...
>
>
|||If I think I'm understanding what you're asking, there's a few ways to do
this. You could add a gratuitous identity column to #temp and use
INSERT...SELECT instead of SELECT INTO. You could loop using a T-SQL
variable until the nodes function returns no nodes, using sql:variable in
the XQuery predicate. You could have also changed the XPath expression to a
FLWOR expression and selected the position, but SQL Server XQuery doesn't
support the "at" portion of "for $x at $y in ..." syntax or the position()
function used outside of the predicate.
Hope this helps,
Bob Beauchemin
http://www.SQLskills.com/blogs/bobb
"Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
news:F327D2A5-07D4-4F37-82BA-23B4BEA60226@.microsoft.com...[vbcol=seagreen]
> Bob,
> Ive spent he entire day chasing ghosts tying to assing a discriminator ,
> its
> easy to code when i know how meny there will be but as these reports are
> dynamic i need to find a way to change rowcount to equal the ordinal, and
> loop till all the rows have been imported
> SELECT t.c.value('local-name(.)', 'varchar(50)') AS Name,
> t.c.value('data(.)', 'Varchar(100)') as Value, '1' as RowNumber
> INTO #ReturnedItem
> FROM
> @.XMLDOC.nodes('/BACSDocument/Data/ARUCS/Advice/OriginatingAccountRecords/OriginatingAccountRecord/ReturnedCreditItem[1]/@.*')
> as t(c)
>
> youve been such a great help so far, think one i can resolve this issue i
> can carry on on my own
> "Bob Beauchemin" wrote:
|||Bob,
Thanks again for the pointers yhoi have to admit ive spend a few hours and
srtill carnt grasp it. I understand what you were saying about the
relationship between table 1 and table 2, that i think i can work out, what
im still struggling with is returning the pivot table for the three addresss
( only for example ). I still can not get the identity colum in using your
previous eamaples. sorry to be a pain but can you pint me in the direction
of an example based of what you have already explained
thanks again for all your help
"Bob Beauchemin" wrote:

> If I think I'm understanding what you're asking, there's a few ways to do
> this. You could add a gratuitous identity column to #temp and use
> INSERT...SELECT instead of SELECT INTO. You could loop using a T-SQL
> variable until the nodes function returns no nodes, using sql:variable in
> the XQuery predicate. You could have also changed the XPath expression to a
> FLWOR expression and selected the position, but SQL Server XQuery doesn't
> support the "at" portion of "for $x at $y in ..." syntax or the position()
> function used outside of the predicate.
> Hope this helps,
> Bob Beauchemin
> http://www.SQLskills.com/blogs/bobb
> "Peter Newman" <PeterNewman@.discussions.microsoft.com> wrote in message
> news:F327D2A5-07D4-4F37-82BA-23B4BEA60226@.microsoft.com...
>
>

Monday, March 12, 2012

help needed to bring in text files..

background: sql2k on nt5.
can someone give me some advice on how to bring in text files located on a
file server directory into a sql server database?
the text files will always have the same structure, but the file names are
not static (but following a naming standard, such as
location+date.txt, such as
or_05102004
wa_05122004
and so on.
so each file will be broung in as a table such as or_05102004, and
wa_05122004 table.
thank you.Will you be loading all of the text files into one table, or does each =type (or, wa, ...) have a different table that it should be loaded into? =
Perhaps you could use BCP or BULK INSERT to import the text files. You =can define a format file if you choose to use BCP. This format file =will define the layout of the file and it will determine how it gets =loaded into the destination table. You could create a stored procedure =that would take a filename as a param and use a bit of dynamic sql to =generate the appropriate BCP statement that uses the appropriate format =file.
Another method would be DTS. You could create a DTS package to insert =the data into SQL Server. This solution might be difficult to maintain =if the file names change often. Then again, you could create a routine =that imports from a standard file name. When you get a new file (on the =network share) you could copy it to the specific location and file name =that your DTS package knows about.
-- Keith
"=3D=3D Steve Pdx=3D=3D" <lins@.nospam.portptld.com> wrote in message =news:uCHOz%23sNEHA.1196@.TK2MSFTNGP11.phx.gbl...
> background: sql2k on nt5.
> > can someone give me some advice on how to bring in text files located =on a
> file server directory into a sql server database?
> the text files will always have the same structure, but the file names =are
> not static (but following a naming standard, such as
> location+date.txt, such as
> or_05102004
> wa_05122004
> and so on.
> > so each file will be broung in as a table such as or_05102004, and
> wa_05122004 table.
> > thank you.
> >

Help needed to attach a DB

I detached a DB, now when I am trying to reattch it I cannot find the
data or the log file. I know I have not deleted anything from the
drives the only thing I am not sure exactly where they were located
prior to the dettach. This is on a test box but we still need to
restore the db. Is there anyway from system tables I could find where
the data file is. I looked for *.mdf files but cannot find the correct
.mdf file. Is it possiblefor the data file to have a differnt
extension? Is it possible for the data file to be located in any
network drive, I did not think this was possible in 2000 but I am using
2005 so I thought I should throw that out there ? Finally will it be
possible to restore the master db then look at the sysdatabse table and
see where it was located prior to the detach, i want to do this only if
it is possible to do so without effecting any other db's on this box.
Any ideas how to troubleshoot this, I am just baffled.
ThanksHi,
By default SQL 2005 uses MDF and LDF extension only. Once you detach the
database all the reference
for that database willl be moved from SQL Server. For me the only way to
identify the location is by restoring the Master database into a new SQL
Server 2005 instance. (Master can be restored only above a Master database in
single user mode). After resting execute the below query to get the
file location of the database you deleted.
select * from sys.master_files
Thanks
Hari
SQL Server MVP
"shub" wrote:
> I detached a DB, now when I am trying to reattch it I cannot find the
> data or the log file. I know I have not deleted anything from the
> drives the only thing I am not sure exactly where they were located
> prior to the dettach. This is on a test box but we still need to
> restore the db. Is there anyway from system tables I could find where
> the data file is. I looked for *.mdf files but cannot find the correct
> ..mdf file. Is it possiblefor the data file to have a differnt
> extension? Is it possible for the data file to be located in any
> network drive, I did not think this was possible in 2000 but I am using
> 2005 so I thought I should throw that out there ? Finally will it be
> possible to restore the master db then look at the sysdatabse table and
> see where it was located prior to the detach, i want to do this only if
> it is possible to do so without effecting any other db's on this box.
> Any ideas how to troubleshoot this, I am just baffled.
> Thanks
>|||Hi
If you have a backup of the database you could use RESTORE FILELISTONLY
command to get the file locations.
John
"shub" wrote:
> I detached a DB, now when I am trying to reattch it I cannot find the
> data or the log file. I know I have not deleted anything from the
> drives the only thing I am not sure exactly where they were located
> prior to the dettach. This is on a test box but we still need to
> restore the db. Is there anyway from system tables I could find where
> the data file is. I looked for *.mdf files but cannot find the correct
> ..mdf file. Is it possiblefor the data file to have a differnt
> extension? Is it possible for the data file to be located in any
> network drive, I did not think this was possible in 2000 but I am using
> 2005 so I thought I should throw that out there ? Finally will it be
> possible to restore the master db then look at the sysdatabse table and
> see where it was located prior to the detach, i want to do this only if
> it is possible to do so without effecting any other db's on this box.
> Any ideas how to troubleshoot this, I am just baffled.
> Thanks
>

Help needed to attach a DB

I detached a DB, now when I am trying to reattch it I cannot find the
data or the log file. I know I have not deleted anything from the
drives the only thing I am not sure exactly where they were located
prior to the dettach. This is on a test box but we still need to
restore the db. Is there anyway from system tables I could find where
the data file is. I looked for *.mdf files but cannot find the correct
.mdf file. Is it possiblefor the data file to have a differnt
extension? Is it possible for the data file to be located in any
network drive, I did not think this was possible in 2000 but I am using
2005 so I thought I should throw that out there ? Finally will it be
possible to restore the master db then look at the sysdatabse table and
see where it was located prior to the detach, i want to do this only if
it is possible to do so without effecting any other db's on this box.
Any ideas how to troubleshoot this, I am just baffled.
ThanksHi,
By default SQL 2005 uses MDF and LDF extension only. Once you detach the
database all the reference
for that database willl be moved from SQL Server. For me the only way to
identify the location is by restoring the Master database into a new SQL
Server 2005 instance. (Master can be restored only above a Master database i
n
single user mode). After resting execute the below query to get the
file location of the database you deleted.
select * from sys.master_files
Thanks
Hari
SQL Server MVP
"shub" wrote:

> I detached a DB, now when I am trying to reattch it I cannot find the
> data or the log file. I know I have not deleted anything from the
> drives the only thing I am not sure exactly where they were located
> prior to the dettach. This is on a test box but we still need to
> restore the db. Is there anyway from system tables I could find where
> the data file is. I looked for *.mdf files but cannot find the correct
> ..mdf file. Is it possiblefor the data file to have a differnt
> extension? Is it possible for the data file to be located in any
> network drive, I did not think this was possible in 2000 but I am using
> 2005 so I thought I should throw that out there ? Finally will it be
> possible to restore the master db then look at the sysdatabse table and
> see where it was located prior to the detach, i want to do this only if
> it is possible to do so without effecting any other db's on this box.
> Any ideas how to troubleshoot this, I am just baffled.
> Thanks
>|||Hi
If you have a backup of the database you could use RESTORE FILELISTONLY
command to get the file locations.
John
"shub" wrote:

> I detached a DB, now when I am trying to reattch it I cannot find the
> data or the log file. I know I have not deleted anything from the
> drives the only thing I am not sure exactly where they were located
> prior to the dettach. This is on a test box but we still need to
> restore the db. Is there anyway from system tables I could find where
> the data file is. I looked for *.mdf files but cannot find the correct
> ..mdf file. Is it possiblefor the data file to have a differnt
> extension? Is it possible for the data file to be located in any
> network drive, I did not think this was possible in 2000 but I am using
> 2005 so I thought I should throw that out there ? Finally will it be
> possible to restore the master db then look at the sysdatabse table and
> see where it was located prior to the detach, i want to do this only if
> it is possible to do so without effecting any other db's on this box.
> Any ideas how to troubleshoot this, I am just baffled.
> Thanks
>

Friday, March 9, 2012

Help Needed in Approach for Error Output In SSIS

Hi i have a issue i am loading data from a flat file into a relational Database and i am loading the data without dropping the Primary and Foreign Key constraints and i am sending the error rows into a error table for each table. This is becoming large over head is there a way to Load the entire error Row as a single Column in one Error Table.

This is occuring coz the input is being parsed and its dividing into columns,

One approach would be to used Derived Column Transformation and Substring all columns but it makes to writing long substring statement as some tables have 80 columns ,

is there a better way to handle these errors so that they can be looked at and Changes can be made to the Data ,

Also one more question is is there a way to Load in case of Duplicates load only the Recent Row By Date Column.

and send the old row according to Date into Error output.

Please suggest me what approach should i go for

Not really

You are best to create individual error tables. It means its easier for the user to see what the data is because it will be correctly split up.

|||

For your first question - why not use a error table with "row number" and "table name" columns and then rather than dumping the whole row into the error table -- log the row number and table name so that you can go back to the exact row and find the data you are having problem with. As the error table now has a standard structure (2 columns), you can use the same error table for logging errors for all the tables you are loading.

For you second question - You are trying to clean up the data (De-Duplication) so its better to stage the tables you are having duplicates in and then load it into the database after deleting the duplicate rows. This is hard to be done in the data-flow task because the order of the data coming in might not be based on date.

|||Another approach to de-duping rows is to use the Rank function - You can find an example using T-SQL here: http://rafael-salas.blogspot.com/2007/04/remove-duplicates-using-t-sql-rank.html and one with a custom component here: http://blogs.conchango.com/jamiethomson/archive/2006/09/12/SSIS_3A00_-Rank-Transform.aspx

On the single column to capture an error, I have seen this implemented by using a text or xml column and generically creating the string to insert based on the row data. However, as Simon noted, this isn't typically very readable, and may require a seperate application to support reviewing the errors.

|||

is there way to log the record number in the Flatfile where the error is occuring and is there a way to log the Error Code and Error Description . Can u please guide me regarding this.

|||I need to capture the Database, Table, Input File Name, Input File Record Number; Key Data (does not need to be entire record), Error Code, Error Desc, Date and Time, SSIS Package/Program|||Basically you need to generate a rowNumber column in the dataflow. There are some samples:

http://support.microsoft.com/kb/908460

http://www.sqlis.com/93.aspx|||Thanks for the information it was very helpful i was thinking to capture the sorce filename and Destination table name too into the error table is there a way to capture this information.|||If you store those values in variables, you can use a derived column transform to bring them into the error flow.|||I am aware of this approach but is there way to store these values into variables , my connection managers are Dynamic i.e from a configurations table in sql server. is there way to capture the src and output names atleast in variable s to write it to error table|||

Dev2624 wrote:

Thanks for the information it was very helpful i was thinking to capture the sorce filename and Destination table name too into the error table is there a way to capture this information.

Why are you creating new threads on this topic? http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2195648&SiteID=1|||Phil's suggestion in the other thread is the same thing I was going to recommend.

Help Needed in Approach for Error Output In SSIS

Hi i have a issue i am loading data from a flat file into a relational Database and i am loading the data without dropping the Primary and Foreign Key constraints and i am sending the error rows into a error table for each table. This is becoming large over head is there a way to Load the entire error Row as a single Column in one Error Table.

This is occuring coz the input is being parsed and its dividing into columns,

One approach would be to used Derived Column Transformation and Substring all columns but it makes to writing long substring statement as some tables have 80 columns ,

is there a better way to handle these errors so that they can be looked at and Changes can be made to the Data ,

Also one more question is is there a way to Load in case of Duplicates load only the Recent Row By Date Column.

and send the old row according to Date into Error output.

Please suggest me what approach should i go for

Not really

You are best to create individual error tables. It means its easier for the user to see what the data is because it will be correctly split up.

|||

For your first question - why not use a error table with "row number" and "table name" columns and then rather than dumping the whole row into the error table -- log the row number and table name so that you can go back to the exact row and find the data you are having problem with. As the error table now has a standard structure (2 columns), you can use the same error table for logging errors for all the tables you are loading.

For you second question - You are trying to clean up the data (De-Duplication) so its better to stage the tables you are having duplicates in and then load it into the database after deleting the duplicate rows. This is hard to be done in the data-flow task because the order of the data coming in might not be based on date.

|||Another approach to de-duping rows is to use the Rank function - You can find an example using T-SQL here: http://rafael-salas.blogspot.com/2007/04/remove-duplicates-using-t-sql-rank.html and one with a custom component here: http://blogs.conchango.com/jamiethomson/archive/2006/09/12/SSIS_3A00_-Rank-Transform.aspx

On the single column to capture an error, I have seen this implemented by using a text or xml column and generically creating the string to insert based on the row data. However, as Simon noted, this isn't typically very readable, and may require a seperate application to support reviewing the errors.

|||

is there way to log the record number in the Flatfile where the error is occuring and is there a way to log the Error Code and Error Description . Can u please guide me regarding this.

|||I need to capture the Database, Table, Input File Name, Input File Record Number; Key Data (does not need to be entire record), Error Code, Error Desc, Date and Time, SSIS Package/Program|||Basically you need to generate a rowNumber column in the dataflow. There are some samples:

http://support.microsoft.com/kb/908460

http://www.sqlis.com/93.aspx|||Thanks for the information it was very helpful i was thinking to capture the sorce filename and Destination table name too into the error table is there a way to capture this information.|||If you store those values in variables, you can use a derived column transform to bring them into the error flow.|||I am aware of this approach but is there way to store these values into variables , my connection managers are Dynamic i.e from a configurations table in sql server. is there way to capture the src and output names atleast in variable s to write it to error table|||

Dev2624 wrote:

Thanks for the information it was very helpful i was thinking to capture the sorce filename and Destination table name too into the error table is there a way to capture this information.

Why are you creating new threads on this topic? http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2195648&SiteID=1|||Phil's suggestion in the other thread is the same thing I was going to recommend.

help needed for Recovring database

I wanted to move my database log file to another drive, but unfortunately I
executed wrong command .
alter database ABC modify file
(name = 'ABC_log',filename= 'D:\Program Files\Microsoft SQL
Server\MSSQL\data\ABC_log.LDF')
instead of
alter database ABC2 modify file
(name = 'ABC2_log',filename= 'D:\Program Files\Microsoft SQL
Server\MSSQL\data\ABC2_log.LDF')
After this, I found my database in Suspect mode, so I executed these commands
sp_configure 'allow updates', 1
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sp_resetstatus 'ABC2'
And restarted DB services, but database was still in suspect mode, after
checking every possibility, I detached that database, I don’t know why I did
this.
But now I am not able to attach database back. When I try doing this it’s
give me following error
Error 5173: Cannot associate files with different databases.
By the way when I attach this mdf file, it changes the logical file name to
ABC_Data.mdf
But when I execute following query, it displays different logical file name
with ABC.mdf
dbcc checkprimaryfile (N'D:\Program Files\Microsoft SQL
Server\MSSQL\Data\ABC2.mdf', 3)
I believe if I change this logical file name I’ll be able to attach database
back.
Kindly help me the recovering database.
Note: I do not have the transaction log backup & current DB backup.
Farhan Iqbal
Error 5173 means, you are trying to attach files that belong to another
database. Check the file names that you are using for your attach.
"Farhan" <Farhan@.discussions.microsoft.com> wrote in message
news:89333AE6-EE72-4863-A73B-C9419112318C@.microsoft.com...
>I wanted to move my database log file to another drive, but unfortunately I
> executed wrong command .
> alter database ABC modify file
> (name = 'ABC_log',filename= 'D:\Program Files\Microsoft SQL
> Server\MSSQL\data\ABC_log.LDF')
> instead of
> alter database ABC2 modify file
> (name = 'ABC2_log',filename= 'D:\Program Files\Microsoft SQL
> Server\MSSQL\data\ABC2_log.LDF')
>
> After this, I found my database in Suspect mode, so I executed these
> commands
> sp_configure 'allow updates', 1
> GO
> RECONFIGURE WITH OVERRIDE
> GO
> EXEC sp_resetstatus 'ABC2'
> And restarted DB services, but database was still in suspect mode, after
> checking every possibility, I detached that database, I don't know why I
> did
> this.
> But now I am not able to attach database back. When I try doing this it's
> give me following error
> Error 5173: Cannot associate files with different databases.
> By the way when I attach this mdf file, it changes the logical file name
> to
> ABC_Data.mdf
> But when I execute following query, it displays different logical file
> name
> with ABC.mdf
> dbcc checkprimaryfile (N'D:\Program Files\Microsoft SQL
> Server\MSSQL\Data\ABC2.mdf', 3)
> I believe if I change this logical file name I'll be able to attach
> database
> back.
> Kindly help me the recovering database.
> Note: I do not have the transaction log backup & current DB backup.
> Farhan Iqbal
>

Wednesday, March 7, 2012

Help needed

Hello,
When I try to run my asp file it gives me this error. :mad:

Technical Information (for support personnel)

Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E07)
Syntax error converting datetime from character string.
/conOpen_inc.asp, line 10

Browser Type:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)

Page:
GET /Default.asp

Anyone can tell me whats happening ? thank youwhat is the format of your Dates ?|||Am sorry I didn't get you but if you mean this one:-

Long date format is dddd, MMMM dd, yyyy
and short date format is M/d/yyyy

is this what you mean ?|||I think what Karolyn ment is what is the dateformat of the character string which holds the date/s versus the dateformat the program converts to (when specified).|||Am sorry I'm not expert in this I was trying to install KEWL (Konwledge Environment Web-Based Learning). Here is the link

http://kewlforge.uwc.ac.za/downloads/kewl.zip
I did follow the instructions step by step.

Any help will be appericiated|||i dont know what is the link doing, but as what Karolyn and Kaiowa mention, check you datetime format. Normally, will get this error is because of dateformat of the character string which holds the date is not recognized by sql server. The date format that you give is from you regional setting is it? you can try to change it to sql server date time format and try again.

Monday, February 27, 2012

Help me. "recbase.cpp"

Hello~
When I run my SQL Server Agent with a rather large database,
I get following event.
"SQL Server assertion: File: <recbase.cpp>, Line=1374"
"SqlDumpExceptionHandler: 1696 Process, Fatal Exception c0000005
EXCEPTION_ACCESS_VIOLATIO"
"SQL Server Stopping..."
So. I found resolution that running "DBCC CheckDB", But No Error Accured.
Can anyone help me with this error, Please
The SQL version is 2000 and all defaults are set for sp_configure
parameters.
jabul, in Seoul, Korea.
jabul,
What service pack level are you on? Do any of these help? Looks like a
SQL Server bug, if none of these help then contact MS PSS.
FIX: An INSERT May Fail with a 3624 Error Message After a Failed Attempt
to Add New Table Column
http://support.microsoft.com/?id=317852
An assertion in the Recbase.cpp file or the Record.inl file may occur
when an operation is performed on an instance of SQL Server
http://support.microsoft.com/?id=828337
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
jabul wrote:
> Hello~
> When I run my SQL Server Agent with a rather large database,
> I get following event.
> "SQL Server assertion: File: <recbase.cpp>, Line=1374"
> "SqlDumpExceptionHandler: 1696 Process, Fatal Exception c0000005
> EXCEPTION_ACCESS_VIOLATIO"
> "SQL Server Stopping..."
> So. I found resolution that running "DBCC CheckDB", But No Error Accured.
> Can anyone help me with this error, Please
> The SQL version is 2000 and all defaults are set for sp_configure
> parameters.
>
> jabul, in Seoul, Korea.
>

Help me. "recbase.cpp"

Hello~
When I run my SQL Server Agent with a rather large database,
I get following event.
"SQL Server assertion: File: <recbase.cpp>, Line=1374"
"SqlDumpExceptionHandler: 1696 Process, Fatal Exception c0000005
EXCEPTION_ACCESS_VIOLATIO"
"SQL Server Stopping..."
So. I found resolution that running "DBCC CheckDB", But No Error Accured.
Can anyone help me with this error, Please
The SQL version is 2000 and all defaults are set for sp_configure
parameters.
jabul, in Seoul, Korea.jabul,
What service pack level are you on? Do any of these help? Looks like a
SQL Server bug, if none of these help then contact MS PSS.
FIX: An INSERT May Fail with a 3624 Error Message After a Failed Attempt
to Add New Table Column
http://support.microsoft.com/?id=317852
An assertion in the Recbase.cpp file or the Record.inl file may occur
when an operation is performed on an instance of SQL Server
http://support.microsoft.com/?id=828337
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
jabul wrote:
> Hello~
> When I run my SQL Server Agent with a rather large database,
> I get following event.
> "SQL Server assertion: File: <recbase.cpp>, Line=1374"
> "SqlDumpExceptionHandler: 1696 Process, Fatal Exception c0000005
> EXCEPTION_ACCESS_VIOLATIO"
> "SQL Server Stopping..."
> So. I found resolution that running "DBCC CheckDB", But No Error Accured.
> Can anyone help me with this error, Please
> The SQL version is 2000 and all defaults are set for sp_configure
> parameters.
>
> jabul, in Seoul, Korea.
>

Help me. "recbase.cpp"

Hello~
When I run my SQL Server Agent with a rather large database,
I get following event.
"SQL Server assertion: File: <recbase.cpp>, Line=1374"
"SqlDumpExceptionHandler: 1696 Process, Fatal Exception c0000005
EXCEPTION_ACCESS_VIOLATIO"
"SQL Server Stopping..."
So. I found resolution that running "DBCC CheckDB", But No Error Accured.
Can anyone help me with this error, Please
The SQL version is 2000 and all defaults are set for sp_configure
parameters.
jabul, in Seoul, Korea.jabul,
What service pack level are you on? Do any of these help? Looks like a
SQL Server bug, if none of these help then contact MS PSS.
FIX: An INSERT May Fail with a 3624 Error Message After a Failed Attempt
to Add New Table Column
http://support.microsoft.com/?id=317852
An assertion in the Recbase.cpp file or the Record.inl file may occur
when an operation is performed on an instance of SQL Server
http://support.microsoft.com/?id=828337
--
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
jabul wrote:
> Hello~
> When I run my SQL Server Agent with a rather large database,
> I get following event.
> "SQL Server assertion: File: <recbase.cpp>, Line=1374"
> "SqlDumpExceptionHandler: 1696 Process, Fatal Exception c0000005
> EXCEPTION_ACCESS_VIOLATIO"
> "SQL Server Stopping..."
> So. I found resolution that running "DBCC CheckDB", But No Error Accured.
> Can anyone help me with this error, Please
> The SQL version is 2000 and all defaults are set for sp_configure
> parameters.
>
> jabul, in Seoul, Korea.
>