Showing posts with label process. Show all posts
Showing posts with label process. Show all posts

Friday, March 30, 2012

Out-of_process error when trying to process a dimension

In my dsv I have a table called OrderDetail. This table has a salescodeid column in it. I have a second table called SalesCodeDetail. There is a relationship between these two tables based on the salescodeid. The Id is the primary key in the SalesCodeDetail table. In my cube I have a dimension of OrderDetail. When I try to add the salescode description from the salescodeDetail table as an attribute in my OrderDetail dimension I get this error.

Here is a more detailed description of this same problem.

I have a fact table that is joined to a dimension table 'Customer' by the customer number. Customer Number is the primary key in the 'Customer' view. I have a second Dimension table called 'SalesRep' which is referenced to the fact table through the customer. The join is SalesRepId, which is primary key on the SalesRep view, and SalesRepId which is on the 'Customer' view but not a key. Also, this relationship between SalesRep and customer does exist in the DSV.

When I try to process this relationship I get the following error: 'OLE DB error: OLE DB or ODBC error: Out-of-process use of OLE DB provider "SQLNCLI.1" with SQL Server is not supported.; 42000.'

The SQL behind the processing is doing an 'OPENROWSET' which is causing the problem. If I take the 'OPENROWSET' out of the query when I run in Query Analyzer, the query runs fine.

So, I need to modify the way AS is creating this processing query.

|||

So, let me check my understanding of the problem. You have a fact table that references the Customer dimension. The Customer dimension holds a SalesRep key which points to the SalesRep dimension. The fact table is assigned a referenced relationship to the SalesRep dimension using the Customer dimension as the intermediate dimension in that relationship. Is that correct?

If so, do you have the SalesRep dimension flagged to be materialized?

Either way, could you post the SQL generated that is causing the error?

Thanks,
Bryan Smith

|||

Yes, you're understanding the problem correctly. Yes, the SalesRep dimension is flagged to be materialized.

Here is the SQL

SELECT [dbo_vw_OrdersAndSalesDetailFact].[ICAndExtExtendedPrice] AS [dbo_vw_OrdersAndSalesDetailFactICAndExtExtendedPrice0_0],[dbo_vw_OrdersAndSalesDetailFact].[ICAndExtOrderQtyInRptUOM] AS [dbo_vw_OrdersAndSalesDetailFactICAndExtOrderQtyInRptUOM0_1],[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId] AS [dbo_vw_OrdersAndSalesDetailFactSoldToAccountId0_2],[dbo_vw_OMSBPCustomer_2].[PrimarySalesRepAccountID] AS [dbo_vw_OMSBPCustomerPrimarySalesRepAccountID2_0]
FROM [dbo].[vw_OrdersAndSalesDetailFact] AS [dbo_vw_OrdersAndSalesDetailFact],
OPENROWSET
(
N'SQLNCLI.1',
N'',
N'[dbo].[vw_OMSBPCustomer]'
)
AS [dbo_vw_OMSBPCustomer_2]
WHERE
(

(
[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId] = [dbo_vw_OMSBPCustomer_2].[CustomerNumber]
)
)

Now if I take this exact SQL and run it in query analyzer I get basically the same error:

Msg 7430, Level 16, State 3, Line 1

Out-of-process use of OLE DB provider "SQLNCLI.1" with SQL Server is not supported.

If I remove the OPENROWSET section as below

SELECT [dbo_vw_OrdersAndSalesDetailFact].[ICAndExtExtendedPrice]

AS [dbo_vw_OrdersAndSalesDetailFactICAndExtExtendedPrice0_0],

[dbo_vw_OrdersAndSalesDetailFact].[ICAndExtOrderQtyInRptUOM]

AS [dbo_vw_OrdersAndSalesDetailFactICAndExtOrderQtyInRptUOM0_1],

[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId]

AS [dbo_vw_OrdersAndSalesDetailFactSoldToAccountId0_2],

[dbo_vw_OMSBPCustomer_2].[PrimarySalesRepAccountID] AS

[dbo_vw_OMSBPCustomerPrimarySalesRepAccountID2_0]

FROM [dbo].[vw_OrdersAndSalesDetailFact] AS [dbo_vw_OrdersAndSalesDetailFact],

-- OPENROWSET

-- (

-- N'SQLNCLI.1',

-- N'',

-- N'[dbo].[vw_OMSBPCustomer]'

-- )

--

[omswrite].[dbo].[vw_OMSBPCustomer] AS [dbo_vw_OMSBPCustomer_2] ****different database here

WHERE

(

(

[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId] = [dbo_vw_OMSBPCustomer_2].[CustomerNumber]

)

)

The customer table and the fact table are in different databases, not sure if that is causing some problems, but don't think it should.

|||

Deselecting the Materialize option should eliminate the problem becase the join will not be performed. If performance drops when querying the Sales Rep data, you may want to try using the .NET provider on your data sources.

B.

|||

This worked. Thanks very much for taking the time to help!

sql

Out-of_process error when trying to process a dimension

In my dsv I have a table called OrderDetail. This table has a salescodeid column in it. I have a second table called SalesCodeDetail. There is a relationship between these two tables based on the salescodeid. The Id is the primary key in the SalesCodeDetail table. In my cube I have a dimension of OrderDetail. When I try to add the salescode description from the salescodeDetail table as an attribute in my OrderDetail dimension I get this error.

Here is a more detailed description of this same problem.

I have a fact table that is joined to a dimension table 'Customer' by the customer number. Customer Number is the primary key in the 'Customer' view. I have a second Dimension table called 'SalesRep' which is referenced to the fact table through the customer. The join is SalesRepId, which is primary key on the SalesRep view, and SalesRepId which is on the 'Customer' view but not a key. Also, this relationship between SalesRep and customer does exist in the DSV.

When I try to process this relationship I get the following error: 'OLE DB error: OLE DB or ODBC error: Out-of-process use of OLE DB provider "SQLNCLI.1" with SQL Server is not supported.; 42000.'

The SQL behind the processing is doing an 'OPENROWSET' which is causing the problem. If I take the 'OPENROWSET' out of the query when I run in Query Analyzer, the query runs fine.

So, I need to modify the way AS is creating this processing query.

|||

So, let me check my understanding of the problem. You have a fact table that references the Customer dimension. The Customer dimension holds a SalesRep key which points to the SalesRep dimension. The fact table is assigned a referenced relationship to the SalesRep dimension using the Customer dimension as the intermediate dimension in that relationship. Is that correct?

If so, do you have the SalesRep dimension flagged to be materialized?

Either way, could you post the SQL generated that is causing the error?

Thanks,
Bryan Smith

|||

Yes, you're understanding the problem correctly. Yes, the SalesRep dimension is flagged to be materialized.

Here is the SQL

SELECT [dbo_vw_OrdersAndSalesDetailFact].[ICAndExtExtendedPrice] AS [dbo_vw_OrdersAndSalesDetailFactICAndExtExtendedPrice0_0],[dbo_vw_OrdersAndSalesDetailFact].[ICAndExtOrderQtyInRptUOM] AS [dbo_vw_OrdersAndSalesDetailFactICAndExtOrderQtyInRptUOM0_1],[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId] AS [dbo_vw_OrdersAndSalesDetailFactSoldToAccountId0_2],[dbo_vw_OMSBPCustomer_2].[PrimarySalesRepAccountID] AS [dbo_vw_OMSBPCustomerPrimarySalesRepAccountID2_0]
FROM [dbo].[vw_OrdersAndSalesDetailFact] AS [dbo_vw_OrdersAndSalesDetailFact],
OPENROWSET
(
N'SQLNCLI.1',
N'',
N'[dbo].[vw_OMSBPCustomer]'
)
AS [dbo_vw_OMSBPCustomer_2]
WHERE
(

(
[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId] = [dbo_vw_OMSBPCustomer_2].[CustomerNumber]
)
)

Now if I take this exact SQL and run it in query analyzer I get basically the same error:

Msg 7430, Level 16, State 3, Line 1

Out-of-process use of OLE DB provider "SQLNCLI.1" with SQL Server is not supported.

If I remove the OPENROWSET section as below

SELECT [dbo_vw_OrdersAndSalesDetailFact].[ICAndExtExtendedPrice]

AS [dbo_vw_OrdersAndSalesDetailFactICAndExtExtendedPrice0_0],

[dbo_vw_OrdersAndSalesDetailFact].[ICAndExtOrderQtyInRptUOM]

AS [dbo_vw_OrdersAndSalesDetailFactICAndExtOrderQtyInRptUOM0_1],

[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId]

AS [dbo_vw_OrdersAndSalesDetailFactSoldToAccountId0_2],

[dbo_vw_OMSBPCustomer_2].[PrimarySalesRepAccountID] AS

[dbo_vw_OMSBPCustomerPrimarySalesRepAccountID2_0]

FROM [dbo].[vw_OrdersAndSalesDetailFact] AS [dbo_vw_OrdersAndSalesDetailFact],

-- OPENROWSET

-- (

-- N'SQLNCLI.1',

-- N'',

-- N'[dbo].[vw_OMSBPCustomer]'

-- )

--

[omswrite].[dbo].[vw_OMSBPCustomer] AS [dbo_vw_OMSBPCustomer_2] ****different database here

WHERE

(

(

[dbo_vw_OrdersAndSalesDetailFact].[SoldToAccountId] = [dbo_vw_OMSBPCustomer_2].[CustomerNumber]

)

)

The customer table and the fact table are in different databases, not sure if that is causing some problems, but don't think it should.

|||

Deselecting the Materialize option should eliminate the problem becase the join will not be performed. If performance drops when querying the Sales Rep data, you may want to try using the .NET provider on your data sources.

B.

|||

This worked. Thanks very much for taking the time to help!

Monday, March 26, 2012

Outer Join in AS2005 cube

I have three tables for the 'Store' dimension...

Store City State

When I include the state name from the State table in the dimension and process the cube, I am missing many stores. Those stores missing don't have a state code in the city table. So, because the cube is generating an inner join between the three tables, I am missing some stores. I need to model an 'outer join' in the relationship between City and State tables. How can I do this in AS 2005?

You can create a named query (in the DataSourceView editor) to include the 3 tables with the wanted outer/inner joins (the named query is the "SELECT ... FROM ..." statement). Then build the 'Store' dimension on it.

Adrian Dumitrascu

Monday, March 12, 2012

OSQL.exe question

Is there a way to process multiple SQL scripts in a single transaction using
osql.exe ?
Ideally, I'd like to be able to start transaction, execute multiple sql
scripts and commit transaction when all of them succeeded or rollback when
there was a failure.
I appreciate your help.
I would copy and paste them together.
-jens S=FC=DFmeyer.
|||"Marek" <nospam@.nowhere.com> wrote in
news:#BmMdSD8FHA.2676@.TK2MSFTNGP15.phx.gbl:

> Is there a way to process multiple SQL scripts in a single transaction
> using osql.exe ?
> Ideally, I'd like to be able to start transaction, execute multiple
> sql scripts and commit transaction when all of them succeeded or
> rollback when there was a failure.
> I appreciate your help.
As far as I know this is not possible in osql, but if you try sqlcmd from
SQL Server 2005, I do believe that you can. However, I have not tried this.
SqlCmd is also available in SQL Server 2005 Express, which is free.
Ole Kristian Bangs
MCT, MCDBA, MCDST, MCSE:Security, MCSE:Messaging
|||"Ole Kristian Bangs" <olekristian.bangas@.masterminds.no> wrote in
news:Xns9717A547BD7D7olekristianbangaas@.207.46.248 .16:

> "Marek" <nospam@.nowhere.com> wrote in
> news:#BmMdSD8FHA.2676@.TK2MSFTNGP15.phx.gbl:
>
> As far as I know this is not possible in osql, but if you try sqlcmd
> from SQL Server 2005, I do believe that you can. However, I have not
> tried this. SqlCmd is also available in SQL Server 2005 Express, which
> is free.
And as Tibor so kindly answered in another group: You can download SqlCmd
here:
http://www.microsoft.com/downloads/d...D09C1D60-A13C-
4479-9B91-9E8B9D835CDC&displaylang=en
Ole Kristian Bangs
MCT, MCDBA, MCDST, MCSE:Security, MCSE:Messaging
|||> As far as I know this is not possible in osql
I guess you could try the :r option to have OSQL read sub-scripts from a mother script. The
sub-scripts cannot have GO. A test is needed to verify that new connections will not be opened for
subscripts, use Profiler for that. Also, :r is not documented for OSQL, but I think it is for
SQLCMD. However, I don't think that error handling will be the easiest thing to accomplish.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Ole Kristian Bangs" <olekristian.bangas@.masterminds.no> wrote in message
news:Xns9717A547BD7D7olekristianbangaas@.207.46.248 .16...
> "Marek" <nospam@.nowhere.com> wrote in
> news:#BmMdSD8FHA.2676@.TK2MSFTNGP15.phx.gbl:
>
> As far as I know this is not possible in osql, but if you try sqlcmd from
> SQL Server 2005, I do believe that you can. However, I have not tried this.
> SqlCmd is also available in SQL Server 2005 Express, which is free.
> --
> Ole Kristian Bangs
> MCT, MCDBA, MCDST, MCSE:Security, MCSE:Messaging

Wednesday, March 7, 2012

OSQL output file contains extra blank lines

I have a process where I am trying to run "sp_helptext" in OSQL and piping
the output to a file so that I could basically generate the "Create
Procedure" statement for a particular Stored Proc. When I run this - I am
getting extra blank lines in the output file.
For example, I run the following OSQL command to generate the pubs.ByRoyalty
stored procedure:
osql -n -h-1 -w180 -SServerName-dpubs -Usa -Psapass -Q"exec sp_Helptext
byroyalty" >ByRoyalty.sql
The contents of ByRoyaly.sql is below...(Note all the annoying blank lines).
Is there any osql switch that could eliminate these blank lines? I've tried
adjusting the -w switch and it has no affect.
Thanks!
CREATE PROCEDURE byroyalty @.percentage int
AS
select au_id from titleauthor
where titleauthor.royaltyper = @.percentage
If you can work with other tools like the query analyzer instead you can get
the desired output using the following script:
USE pubs
CREATE TABLE #ByRoyalty (output varchar(8000))
INSERT #ByRoyalty
EXEC sp_helptext byroyalty
SELECT * FROM #ByRoyalty
The trick now is to find a way to send the output to a file
Hope it helps
"TJTODD" wrote:

> I have a process where I am trying to run "sp_helptext" in OSQL and piping
> the output to a file so that I could basically generate the "Create
> Procedure" statement for a particular Stored Proc. When I run this - I am
> getting extra blank lines in the output file.
> For example, I run the following OSQL command to generate the pubs.ByRoyalty
> stored procedure:
> osql -n -h-1 -w180 -SServerName-dpubs -Usa -Psapass -Q"exec sp_Helptext
> byroyalty" >ByRoyalty.sql
> The contents of ByRoyaly.sql is below...(Note all the annoying blank lines).
> Is there any osql switch that could eliminate these blank lines? I've tried
> adjusting the -w switch and it has no affect.
> Thanks!
>
> CREATE PROCEDURE byroyalty @.percentage int
>
> AS
>
> select au_id from titleauthor
>
> where titleauthor.royaltyper = @.percentage
>
>

OSQL output file contains extra blank lines

I have a process where I am trying to run "sp_helptext" in OSQL and piping
the output to a file so that I could basically generate the "Create
Procedure" statement for a particular Stored Proc. When I run this - I am
getting extra blank lines in the output file.
For example, I run the following OSQL command to generate the pubs.ByRoyalty
stored procedure:
osql -n -h-1 -w180 -SServerName-dpubs -Usa -Psapass -Q"exec sp_Helptext
byroyalty" >ByRoyalty.sql
The contents of ByRoyaly.sql is below...(Note all the annoying blank lines).
Is there any osql switch that could eliminate these blank lines? I've tried
adjusting the -w switch and it has no affect.
Thanks!
CREATE PROCEDURE byroyalty @.percentage int
AS
select au_id from titleauthor
where titleauthor.royaltyper = @.percentageIf you can work with other tools like the query analyzer instead you can get
the desired output using the following script:
USE pubs
CREATE TABLE #ByRoyalty (output varchar(8000))
INSERT #ByRoyalty
EXEC sp_helptext byroyalty
SELECT * FROM #ByRoyalty
The trick now is to find a way to send the output to a file
Hope it helps
"TJTODD" wrote:

> I have a process where I am trying to run "sp_helptext" in OSQL and piping
> the output to a file so that I could basically generate the "Create
> Procedure" statement for a particular Stored Proc. When I run this - I am
> getting extra blank lines in the output file.
> For example, I run the following OSQL command to generate the pubs.ByRoyal
ty
> stored procedure:
> osql -n -h-1 -w180 -SServerName-dpubs -Usa -Psapass -Q"exec sp_Helptext
> byroyalty" >ByRoyalty.sql
> The contents of ByRoyaly.sql is below...(Note all the annoying blank lines
).
> Is there any osql switch that could eliminate these blank lines? I've tri
ed
> adjusting the -w switch and it has no affect.
> Thanks!
>
> CREATE PROCEDURE byroyalty @.percentage int
>
> AS
>
> select au_id from titleauthor
>
> where titleauthor.royaltyper = @.percentage
>
>

OSQL output file contains extra blank lines

I have a process where I am trying to run "sp_helptext" in OSQL and piping
the output to a file so that I could basically generate the "Create
Procedure" statement for a particular Stored Proc. When I run this - I am
getting extra blank lines in the output file.
For example, I run the following OSQL command to generate the pubs.ByRoyalty
stored procedure:
osql -n -h-1 -w180 -SServerName-dpubs -Usa -Psapass -Q"exec sp_Helptext
byroyalty" >ByRoyalty.sql
The contents of ByRoyaly.sql is below...(Note all the annoying blank lines).
Is there any osql switch that could eliminate these blank lines? I've tried
adjusting the -w switch and it has no affect.
Thanks!
CREATE PROCEDURE byroyalty @.percentage int
AS
select au_id from titleauthor
where titleauthor.royaltyper = @.percentageIf you can work with other tools like the query analyzer instead you can get
the desired output using the following script:
USE pubs
CREATE TABLE #ByRoyalty (output varchar(8000))
INSERT #ByRoyalty
EXEC sp_helptext byroyalty
SELECT * FROM #ByRoyalty
The trick now is to find a way to send the output to a file
Hope it helps
"TJTODD" wrote:
> I have a process where I am trying to run "sp_helptext" in OSQL and piping
> the output to a file so that I could basically generate the "Create
> Procedure" statement for a particular Stored Proc. When I run this - I am
> getting extra blank lines in the output file.
> For example, I run the following OSQL command to generate the pubs.ByRoyalty
> stored procedure:
> osql -n -h-1 -w180 -SServerName-dpubs -Usa -Psapass -Q"exec sp_Helptext
> byroyalty" >ByRoyalty.sql
> The contents of ByRoyaly.sql is below...(Note all the annoying blank lines).
> Is there any osql switch that could eliminate these blank lines? I've tried
> adjusting the -w switch and it has no affect.
> Thanks!
>
> CREATE PROCEDURE byroyalty @.percentage int
>
> AS
>
> select au_id from titleauthor
>
> where titleauthor.royaltyper = @.percentage
>
>

Saturday, February 25, 2012

oSQL - How do I run all .SQL files in a folder by running one batch

Hello. I run into many instances where I have 50+ .sql scripts that I need
to run on multiple SQL installs. I want to automate this process some by
being able to drop all my .sql scripts into a folder and then click on my
batch file that will run all scripts in that folder, and create a log file
with the results.
For Example, my Folder has:
01 Sproc1.sql
02 Sproc2.sql
03 Sproc3.sql
etc...
The batch should be able to go through each file and run them one by one.
I know I can 'pipe' all scripts into one file and just run that one file,
but I've run into some issues with that method.
Any help is greatly appreciated!
Thanks,
TomI would use "xp_cmdshell" to get the name of all the SQL scripts into a
temporary table using the DOS 'dir /b <your directory>' command, then
process through each file in the temporary table one file at time and again
use "xp_cmdshell" to issue an "OSQL -E -S<yourserver> -i <your file> -o
<outputfile>" for each file. Hope this is enough to give you clues on how
to do this.
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Tom" <none@.none.com> wrote in message
news:ublnUExUEHA.2988@.TK2MSFTNGP10.phx.gbl...
> Hello. I run into many instances where I have 50+ .sql scripts that I
need
> to run on multiple SQL installs. I want to automate this process some by
> being able to drop all my .sql scripts into a folder and then click on my
> batch file that will run all scripts in that folder, and create a log file
> with the results.
>
> For Example, my Folder has:
> 01 Sproc1.sql
> 02 Sproc2.sql
> 03 Sproc3.sql
> etc...
> The batch should be able to go through each file and run them one by one.
>
> I know I can 'pipe' all scripts into one file and just run that one file,
> but I've run into some issues with that method.
> Any help is greatly appreciated!
> Thanks,
>
> Tom
>|||> I want to automate this process some by
> being able to drop all my .sql scripts into a folder and then click on my
> batch file that will run all scripts in that folder, and create a log file
> with the results.
The MS-DOS FOR command is pretty powerful
RunScripts.bat
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %f IN (%1\*.sql) DO osql -i %f <-- also add other switches for
osql.exe
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"|||> FOR %f IN (%1\*.sql) DO osql -i %f <- add other switches for
> osql.exe
> GOTO End
Sorry about the wrap, just wanted to clear this up, that line that just says
osql.exe is part of my comment on the line above it. It is not a command in
the batch file. The line above it is supposed to end with this:
<-- also add other switches for osql.exe
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"|||Hi
If you require the output from each file to be kept separate then your
method is an easy way to differentiate the output (check for empty files an
easy way to test it worked!).
If you don't require separate files my preference is to do something like:
for %f in (*.sql) do echo :r %f >> files.msql
Then run osql -E -i files.msql this will run multiple files on one
connection which should be alot faster.
John
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:eiJT4TxUEHA.2028@.TK2MSFTNGP11.phx.gbl...
> Sorry about the wrap, just wanted to clear this up, that line that just
says
> osql.exe is part of my comment on the line above it. It is not a command
in
> the batch file. The line above it is supposed to end with this:
> <-- also add other switches for osql.exe
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>|||Thanks. The script is not running though... I'm getting:
c:\TEMP\runscripts c:\scripts
1\*.sql was not expected at this time
I'm not the best with %"" stuff! Any ideas?
Thanks much!
Tom
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:eiJT4TxUEHA.2028@.TK2MSFTNGP11.phx.gbl...
> Sorry about the wrap, just wanted to clear this up, that line that just
says
> osql.exe is part of my comment on the line above it. It is not a command
in
> the batch file. The line above it is supposed to end with this:
> <-- also add other switches for osql.exe
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>|||> c:\TEMP\runscripts c:\scripts
> 1\*.sql was not expected at this time
OOPS! That's what I get for typing it in here and not playing with it
first. Sorry!
Here is the working version of runscripts.bat:
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %%f IN (%1\*.sql) DO osql -S server -E -d database -i %%f
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Note that %1 always has one % sign, and %%f always has two. if you look at
the first page of the help for the FOR command (C:\> HELP FOR) you will note
a statement that says if you use the FOR command in a batch file, that
%variable should be %%variable. %1, however is a parameter, not a variable.
Also, you might look at John Bell's remarks. Concatenating the scripts into
one file will reduce all the connection opening times, if that's an issue
for you. In fact, you can get the batch file to do that for you:
Contents of runscripts2.bat (tested and verified this time):
@.ECHO OFF
IF "%1"=="" GOTO Syntax
IF EXIST %TEMP%\BigScript.sql DEL %TEMP%\BigScript.sql
FOR %%f IN (%1\*.sql) DO TYPE %%f >> %TEMP%\BigScript.sql
osql -S pc5055\MLabosh -E -d Northwind -i %TEMP%\BigScript.sql
DEL %TEMP%\BigScript.sql
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
As an option, you might insert a PAUSE right before the call to osql in case
you'd like to review bigscript.sql before running it. You could also remove
the second DEL command if you want to keep the bigscript.sql
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"|||Hi
Just to add!!
I use ~ (tilda) to remove quotes around a variable (if they exist) and then
add them manually so that spaces in file/directory names can be used.
e.g ("%~1\*.sql")
John
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:OnZwKg0UEHA.3016@.tk2msftngp13.phx.gbl...
> OOPS! That's what I get for typing it in here and not playing with it
> first. Sorry!
> Here is the working version of runscripts.bat:
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> FOR %%f IN (%1\*.sql) DO osql -S server -E -d database -i %%f
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> Note that %1 always has one % sign, and %%f always has two. if you look
at
> the first page of the help for the FOR command (C:\> HELP FOR) you will
note
> a statement that says if you use the FOR command in a batch file, that
> %variable should be %%variable. %1, however is a parameter, not a
variable.
> Also, you might look at John Bell's remarks. Concatenating the scripts
into
> one file will reduce all the connection opening times, if that's an issue
> for you. In fact, you can get the batch file to do that for you:
> Contents of runscripts2.bat (tested and verified this time):
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> IF EXIST %TEMP%\BigScript.sql DEL %TEMP%\BigScript.sql
> FOR %%f IN (%1\*.sql) DO TYPE %%f >> %TEMP%\BigScript.sql
> osql -S pc5055\MLabosh -E -d Northwind -i %TEMP%\BigScript.sql
> DEL %TEMP%\BigScript.sql
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> As an option, you might insert a PAUSE right before the call to osql in
case
> you'd like to review bigscript.sql before running it. You could also
remove
> the second DEL command if you want to keep the bigscript.sql
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>|||Thank you guys! Getting closer in that the error is gone and it is running
(some of) the scripts in the folder. In the folder c:\scripts I created two
test scripts:
Script1.sql (Use Northwind select * from orders where orderID = 10317 )
Script2.sql (Use Northwind select * from orders where employeeID = 5 )
They are both just lookups for Northwind. Both of them run fine
individually and return results, but when using the batch only one was being
returned (scripts2.sql). So, I tried swapping the names of the files to see
if only the 2nd one would run.. and this time the log showed that they both
ran.
Here's what I used:
--
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %%f IN (%1\*.sql) DO osql -Usa -Ppasswordhere -Spryancompaq -i
%%f -oC:\log.txt
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
--
Could it be that it is actually running both, but that it overwrites the Log
file after the first one? If so, I wonder why it displayed both results the
2nd time. Perhaps the order of the scripts has something to do with it?
(Of course, the order they are run is important in many cases... we usually
name our scripts starting with 01script, 02script, etc.. I wonder if this
batch would run them but that order.. will try some tests..)
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:uzoT5D5UEHA.412@.TK2MSFTNGP10.phx.gbl...
> Hi
> Just to add!!
> I use ~ (tilda) to remove quotes around a variable (if they exist) and
then
> add them manually so that spaces in file/directory names can be used.
> e.g ("%~1\*.sql")
> John
> "Mike Labosh" <mlabosh@.hotmail.com> wrote in message
> news:OnZwKg0UEHA.3016@.tk2msftngp13.phx.gbl...
> at
> note
> variable.
> into
issue[vbcol=seagreen]
> case
> remove
>|||Hi
With the fixed log file you will overwrite it for each file, therefore only
the last output will be given
If you require one output file see my previous post, if infividual files are
required try:
FOR %%f IN ("%~1\*.sql") DO osql -Usa -Ppasswordhere -Spryancompaq -i %%f -o
%%~nf.txt
John
"Tom" <none@.none.com> wrote in message
news:uTBBqP6UEHA.3476@.tk2msftngp13.phx.gbl...
> Thank you guys! Getting closer in that the error is gone and it is
running
> (some of) the scripts in the folder. In the folder c:\scripts I created
two
> test scripts:
> Script1.sql (Use Northwind select * from orders where orderID = 10317 )
> Script2.sql (Use Northwind select * from orders where employeeID = 5 )
> They are both just lookups for Northwind. Both of them run fine
> individually and return results, but when using the batch only one was
being
> returned (scripts2.sql). So, I tried swapping the names of the files to
see
> if only the 2nd one would run.. and this time the log showed that they
both
> ran.
> Here's what I used:
> --
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> FOR %%f IN (%1\*.sql) DO osql -Usa -Ppasswordhere -Spryancompaq -i
> %%f -oC:\log.txt
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> --
> Could it be that it is actually running both, but that it overwrites the
Log
> file after the first one? If so, I wonder why it displayed both results
the
> 2nd time. Perhaps the order of the scripts has something to do with it?
> (Of course, the order they are run is important in many cases... we
usually
> name our scripts starting with 01script, 02script, etc.. I wonder if this
> batch would run them but that order.. will try some tests..)
>
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:uzoT5D5UEHA.412@.TK2MSFTNGP10.phx.gbl...
> then
look[vbcol=seagreen]
will[vbcol=seagreen]
scripts[vbcol=seagreen]
> issue
in[vbcol=seagreen]
>

oSQL - How do I run all .SQL files in a folder by running one batch

Hello. I run into many instances where I have 50+ .sql scripts that I need
to run on multiple SQL installs. I want to automate this process some by
being able to drop all my .sql scripts into a folder and then click on my
batch file that will run all scripts in that folder, and create a log file
with the results.
For Example, my Folder has:
01 Sproc1.sql
02 Sproc2.sql
03 Sproc3.sql
etc...
The batch should be able to go through each file and run them one by one.
I know I can 'pipe' all scripts into one file and just run that one file,
but I've run into some issues with that method.
Any help is greatly appreciated!
Thanks,
Tom
I would use "xp_cmdshell" to get the name of all the SQL scripts into a
temporary table using the DOS 'dir /b <your directory>' command, then
process through each file in the temporary table one file at time and again
use "xp_cmdshell" to issue an "OSQL -E -S<yourserver> -i <your file> -o
<outputfile>" for each file. Hope this is enough to give you clues on how
to do this.
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Tom" <none@.none.com> wrote in message
news:ublnUExUEHA.2988@.TK2MSFTNGP10.phx.gbl...
> Hello. I run into many instances where I have 50+ .sql scripts that I
need
> to run on multiple SQL installs. I want to automate this process some by
> being able to drop all my .sql scripts into a folder and then click on my
> batch file that will run all scripts in that folder, and create a log file
> with the results.
>
> For Example, my Folder has:
> 01 Sproc1.sql
> 02 Sproc2.sql
> 03 Sproc3.sql
> etc...
> The batch should be able to go through each file and run them one by one.
>
> I know I can 'pipe' all scripts into one file and just run that one file,
> but I've run into some issues with that method.
> Any help is greatly appreciated!
> Thanks,
>
> Tom
>
|||> I want to automate this process some by
> being able to drop all my .sql scripts into a folder and then click on my
> batch file that will run all scripts in that folder, and create a log file
> with the results.
The MS-DOS FOR command is pretty powerful
RunScripts.bat
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %f IN (%1\*.sql) DO osql -i %f <-- also add other switches for
osql.exe
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"
|||> FOR %f IN (%1\*.sql) DO osql -i %f <- add other switches for
> osql.exe
> GOTO End
Sorry about the wrap, just wanted to clear this up, that line that just says
osql.exe is part of my comment on the line above it. It is not a command in
the batch file. The line above it is supposed to end with this:
<-- also add other switches for osql.exe
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"
|||Hi
If you require the output from each file to be kept separate then your
method is an easy way to differentiate the output (check for empty files an
easy way to test it worked!).
If you don't require separate files my preference is to do something like:
for %f in (*.sql) do echo :r %f >> files.msql
Then run osql -E -i files.msql this will run multiple files on one
connection which should be alot faster.
John
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:eiJT4TxUEHA.2028@.TK2MSFTNGP11.phx.gbl...
> Sorry about the wrap, just wanted to clear this up, that line that just
says
> osql.exe is part of my comment on the line above it. It is not a command
in
> the batch file. The line above it is supposed to end with this:
> <-- also add other switches for osql.exe
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>
|||Thanks. The script is not running though... I'm getting:
c:\TEMP\runscripts c:\scripts
1\*.sql was not expected at this time
I'm not the best with %"" stuff! Any ideas?
Thanks much!
Tom
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:eiJT4TxUEHA.2028@.TK2MSFTNGP11.phx.gbl...
> Sorry about the wrap, just wanted to clear this up, that line that just
says
> osql.exe is part of my comment on the line above it. It is not a command
in
> the batch file. The line above it is supposed to end with this:
> <-- also add other switches for osql.exe
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>
|||> c:\TEMP\runscripts c:\scripts
> 1\*.sql was not expected at this time
OOPS! That's what I get for typing it in here and not playing with it
first. Sorry!
Here is the working version of runscripts.bat:
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %%f IN (%1\*.sql) DO osql -S server -E -d database -i %%f
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Note that %1 always has one % sign, and %%f always has two. if you look at
the first page of the help for the FOR command (C:\> HELP FOR) you will note
a statement that says if you use the FOR command in a batch file, that
%variable should be %%variable. %1, however is a parameter, not a variable.
Also, you might look at John Bell's remarks. Concatenating the scripts into
one file will reduce all the connection opening times, if that's an issue
for you. In fact, you can get the batch file to do that for you:
Contents of runscripts2.bat (tested and verified this time):
@.ECHO OFF
IF "%1"=="" GOTO Syntax
IF EXIST %TEMP%\BigScript.sql DEL %TEMP%\BigScript.sql
FOR %%f IN (%1\*.sql) DO TYPE %%f >> %TEMP%\BigScript.sql
osql -S pc5055\MLabosh -E -d Northwind -i %TEMP%\BigScript.sql
DEL %TEMP%\BigScript.sql
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
As an option, you might insert a PAUSE right before the call to osql in case
you'd like to review bigscript.sql before running it. You could also remove
the second DEL command if you want to keep the bigscript.sql
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"
|||Hi
Just to add!!
I use ~ (tilda) to remove quotes around a variable (if they exist) and then
add them manually so that spaces in file/directory names can be used.
e.g ("%~1\*.sql")
John
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:OnZwKg0UEHA.3016@.tk2msftngp13.phx.gbl...
> OOPS! That's what I get for typing it in here and not playing with it
> first. Sorry!
> Here is the working version of runscripts.bat:
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> FOR %%f IN (%1\*.sql) DO osql -S server -E -d database -i %%f
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> Note that %1 always has one % sign, and %%f always has two. if you look
at
> the first page of the help for the FOR command (C:\> HELP FOR) you will
note
> a statement that says if you use the FOR command in a batch file, that
> %variable should be %%variable. %1, however is a parameter, not a
variable.
> Also, you might look at John Bell's remarks. Concatenating the scripts
into
> one file will reduce all the connection opening times, if that's an issue
> for you. In fact, you can get the batch file to do that for you:
> Contents of runscripts2.bat (tested and verified this time):
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> IF EXIST %TEMP%\BigScript.sql DEL %TEMP%\BigScript.sql
> FOR %%f IN (%1\*.sql) DO TYPE %%f >> %TEMP%\BigScript.sql
> osql -S pc5055\MLabosh -E -d Northwind -i %TEMP%\BigScript.sql
> DEL %TEMP%\BigScript.sql
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> As an option, you might insert a PAUSE right before the call to osql in
case
> you'd like to review bigscript.sql before running it. You could also
remove
> the second DEL command if you want to keep the bigscript.sql
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>
|||Thank you guys! Getting closer in that the error is gone and it is running
(some of) the scripts in the folder. In the folder c:\scripts I created two
test scripts:
Script1.sql (Use Northwind select * from orders where orderID = 10317 )
Script2.sql (Use Northwind select * from orders where employeeID = 5 )
They are both just lookups for Northwind. Both of them run fine
individually and return results, but when using the batch only one was being
returned (scripts2.sql). So, I tried swapping the names of the files to see
if only the 2nd one would run.. and this time the log showed that they both
ran.
Here's what I used:
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %%f IN (%1\*.sql) DO osql -Usa -Ppasswordhere -Spryancompaq -i
%%f -oC:\log.txt
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Could it be that it is actually running both, but that it overwrites the Log
file after the first one? If so, I wonder why it displayed both results the
2nd time. Perhaps the order of the scripts has something to do with it?
(Of course, the order they are run is important in many cases... we usually
name our scripts starting with 01script, 02script, etc.. I wonder if this
batch would run them but that order.. will try some tests..)
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:uzoT5D5UEHA.412@.TK2MSFTNGP10.phx.gbl...
> Hi
> Just to add!!
> I use ~ (tilda) to remove quotes around a variable (if they exist) and
then[vbcol=seagreen]
> add them manually so that spaces in file/directory names can be used.
> e.g ("%~1\*.sql")
> John
> "Mike Labosh" <mlabosh@.hotmail.com> wrote in message
> news:OnZwKg0UEHA.3016@.tk2msftngp13.phx.gbl...
> at
> note
> variable.
> into
issue
> case
> remove
>
|||Hi
With the fixed log file you will overwrite it for each file, therefore only
the last output will be given
If you require one output file see my previous post, if infividual files are
required try:
FOR %%f IN ("%~1\*.sql") DO osql -Usa -Ppasswordhere -Spryancompaq -i %%f -o
%%~nf.txt
John
"Tom" <none@.none.com> wrote in message
news:uTBBqP6UEHA.3476@.tk2msftngp13.phx.gbl...
> Thank you guys! Getting closer in that the error is gone and it is
running
> (some of) the scripts in the folder. In the folder c:\scripts I created
two
> test scripts:
> Script1.sql (Use Northwind select * from orders where orderID = 10317 )
> Script2.sql (Use Northwind select * from orders where employeeID = 5 )
> They are both just lookups for Northwind. Both of them run fine
> individually and return results, but when using the batch only one was
being
> returned (scripts2.sql). So, I tried swapping the names of the files to
see
> if only the 2nd one would run.. and this time the log showed that they
both
> ran.
> Here's what I used:
> --
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> FOR %%f IN (%1\*.sql) DO osql -Usa -Ppasswordhere -Spryancompaq -i
> %%f -oC:\log.txt
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> --
> Could it be that it is actually running both, but that it overwrites the
Log
> file after the first one? If so, I wonder why it displayed both results
the
> 2nd time. Perhaps the order of the scripts has something to do with it?
> (Of course, the order they are run is important in many cases... we
usually[vbcol=seagreen]
> name our scripts starting with 01script, 02script, etc.. I wonder if this
> batch would run them but that order.. will try some tests..)
>
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:uzoT5D5UEHA.412@.TK2MSFTNGP10.phx.gbl...
> then
look[vbcol=seagreen]
will[vbcol=seagreen]
scripts[vbcol=seagreen]
> issue
in
>

oSQL - How do I run all .SQL files in a folder by running one batch

Hello. I run into many instances where I have 50+ .sql scripts that I need
to run on multiple SQL installs. I want to automate this process some by
being able to drop all my .sql scripts into a folder and then click on my
batch file that will run all scripts in that folder, and create a log file
with the results.
For Example, my Folder has:
01 Sproc1.sql
02 Sproc2.sql
03 Sproc3.sql
etc...
The batch should be able to go through each file and run them one by one.
I know I can 'pipe' all scripts into one file and just run that one file,
but I've run into some issues with that method.
Any help is greatly appreciated!
Thanks,
Tom
I would use "xp_cmdshell" to get the name of all the SQL scripts into a
temporary table using the DOS 'dir /b <your directory>' command, then
process through each file in the temporary table one file at time and again
use "xp_cmdshell" to issue an "OSQL -E -S<yourserver> -i <your file> -o
<outputfile>" for each file. Hope this is enough to give you clues on how
to do this.
----
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Tom" <none@.none.com> wrote in message
news:ublnUExUEHA.2988@.TK2MSFTNGP10.phx.gbl...
> Hello. I run into many instances where I have 50+ .sql scripts that I
need
> to run on multiple SQL installs. I want to automate this process some by
> being able to drop all my .sql scripts into a folder and then click on my
> batch file that will run all scripts in that folder, and create a log file
> with the results.
>
> For Example, my Folder has:
> 01 Sproc1.sql
> 02 Sproc2.sql
> 03 Sproc3.sql
> etc...
> The batch should be able to go through each file and run them one by one.
>
> I know I can 'pipe' all scripts into one file and just run that one file,
> but I've run into some issues with that method.
> Any help is greatly appreciated!
> Thanks,
>
> Tom
>
|||> I want to automate this process some by
> being able to drop all my .sql scripts into a folder and then click on my
> batch file that will run all scripts in that folder, and create a log file
> with the results.
The MS-DOS FOR command is pretty powerful
RunScripts.bat
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %f IN (%1\*.sql) DO osql -i %f <-- also add other switches for
osql.exe
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"
|||> FOR %f IN (%1\*.sql) DO osql -i %f <- add other switches for
> osql.exe
> GOTO End
Sorry about the wrap, just wanted to clear this up, that line that just says
osql.exe is part of my comment on the line above it. It is not a command in
the batch file. The line above it is supposed to end with this:
<-- also add other switches for osql.exe
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"
|||Hi
If you require the output from each file to be kept separate then your
method is an easy way to differentiate the output (check for empty files an
easy way to test it worked!).
If you don't require separate files my preference is to do something like:
for %f in (*.sql) do echo :r %f >> files.msql
Then run osql -E -i files.msql this will run multiple files on one
connection which should be alot faster.
John
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:eiJT4TxUEHA.2028@.TK2MSFTNGP11.phx.gbl...
> Sorry about the wrap, just wanted to clear this up, that line that just
says
> osql.exe is part of my comment on the line above it. It is not a command
in
> the batch file. The line above it is supposed to end with this:
> <-- also add other switches for osql.exe
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>
|||Thanks. The script is not running though... I'm getting:
c:\TEMP\runscripts c:\scripts
1\*.sql was not expected at this time
I'm not the best with %"" stuff! Any ideas?
Thanks much!
Tom
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:eiJT4TxUEHA.2028@.TK2MSFTNGP11.phx.gbl...
> Sorry about the wrap, just wanted to clear this up, that line that just
says
> osql.exe is part of my comment on the line above it. It is not a command
in
> the batch file. The line above it is supposed to end with this:
> <-- also add other switches for osql.exe
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>
|||> c:\TEMP\runscripts c:\scripts
> 1\*.sql was not expected at this time
OOPS! That's what I get for typing it in here and not playing with it
first. Sorry!
Here is the working version of runscripts.bat:
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %%f IN (%1\*.sql) DO osql -S server -E -d database -i %%f
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Note that %1 always has one % sign, and %%f always has two. if you look at
the first page of the help for the FOR command (C:\> HELP FOR) you will note
a statement that says if you use the FOR command in a batch file, that
%variable should be %%variable. %1, however is a parameter, not a variable.
Also, you might look at John Bell's remarks. Concatenating the scripts into
one file will reduce all the connection opening times, if that's an issue
for you. In fact, you can get the batch file to do that for you:
Contents of runscripts2.bat (tested and verified this time):
@.ECHO OFF
IF "%1"=="" GOTO Syntax
IF EXIST %TEMP%\BigScript.sql DEL %TEMP%\BigScript.sql
FOR %%f IN (%1\*.sql) DO TYPE %%f >> %TEMP%\BigScript.sql
osql -S pc5055\MLabosh -E -d Northwind -i %TEMP%\BigScript.sql
DEL %TEMP%\BigScript.sql
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
As an option, you might insert a PAUSE right before the call to osql in case
you'd like to review bigscript.sql before running it. You could also remove
the second DEL command if you want to keep the bigscript.sql
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"
|||Hi
Just to add!!
I use ~ (tilda) to remove quotes around a variable (if they exist) and then
add them manually so that spaces in file/directory names can be used.
e.g ("%~1\*.sql")
John
"Mike Labosh" <mlabosh@.hotmail.com> wrote in message
news:OnZwKg0UEHA.3016@.tk2msftngp13.phx.gbl...
> OOPS! That's what I get for typing it in here and not playing with it
> first. Sorry!
> Here is the working version of runscripts.bat:
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> FOR %%f IN (%1\*.sql) DO osql -S server -E -d database -i %%f
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> Note that %1 always has one % sign, and %%f always has two. if you look
at
> the first page of the help for the FOR command (C:\> HELP FOR) you will
note
> a statement that says if you use the FOR command in a batch file, that
> %variable should be %%variable. %1, however is a parameter, not a
variable.
> Also, you might look at John Bell's remarks. Concatenating the scripts
into
> one file will reduce all the connection opening times, if that's an issue
> for you. In fact, you can get the batch file to do that for you:
> Contents of runscripts2.bat (tested and verified this time):
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> IF EXIST %TEMP%\BigScript.sql DEL %TEMP%\BigScript.sql
> FOR %%f IN (%1\*.sql) DO TYPE %%f >> %TEMP%\BigScript.sql
> osql -S pc5055\MLabosh -E -d Northwind -i %TEMP%\BigScript.sql
> DEL %TEMP%\BigScript.sql
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> As an option, you might insert a PAUSE right before the call to osql in
case
> you'd like to review bigscript.sql before running it. You could also
remove
> the second DEL command if you want to keep the bigscript.sql
> --
> Peace & happy computing,
> Mike Labosh, MCSD
> "SELECT * FROM Users WHERE Clue > 0"
>
|||Thank you guys! Getting closer in that the error is gone and it is running
(some of) the scripts in the folder. In the folder c:\scripts I created two
test scripts:
Script1.sql (Use Northwind select * from orders where orderID = 10317 )
Script2.sql (Use Northwind select * from orders where employeeID = 5 )
They are both just lookups for Northwind. Both of them run fine
individually and return results, but when using the batch only one was being
returned (scripts2.sql). So, I tried swapping the names of the files to see
if only the 2nd one would run.. and this time the log showed that they both
ran.
Here's what I used:
@.ECHO OFF
IF "%1"=="" GOTO Syntax
FOR %%f IN (%1\*.sql) DO osql -Usa -Ppasswordhere -Spryancompaq -i
%%f -oC:\log.txt
GOTO End
:Syntax
ECHO Please specify a folder like this:
ECHO RunScripts c:\scripts
ECHO to run all the SQL scripts in that folder
:End
ECHO.
Could it be that it is actually running both, but that it overwrites the Log
file after the first one? If so, I wonder why it displayed both results the
2nd time. Perhaps the order of the scripts has something to do with it?
(Of course, the order they are run is important in many cases... we usually
name our scripts starting with 01script, 02script, etc.. I wonder if this
batch would run them but that order.. will try some tests..)
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:uzoT5D5UEHA.412@.TK2MSFTNGP10.phx.gbl...
> Hi
> Just to add!!
> I use ~ (tilda) to remove quotes around a variable (if they exist) and
then[vbcol=seagreen]
> add them manually so that spaces in file/directory names can be used.
> e.g ("%~1\*.sql")
> John
> "Mike Labosh" <mlabosh@.hotmail.com> wrote in message
> news:OnZwKg0UEHA.3016@.tk2msftngp13.phx.gbl...
> at
> note
> variable.
> into
issue
> case
> remove
>
|||Hi
With the fixed log file you will overwrite it for each file, therefore only
the last output will be given
If you require one output file see my previous post, if infividual files are
required try:
FOR %%f IN ("%~1\*.sql") DO osql -Usa -Ppasswordhere -Spryancompaq -i %%f -o
%%~nf.txt
John
"Tom" <none@.none.com> wrote in message
news:uTBBqP6UEHA.3476@.tk2msftngp13.phx.gbl...
> Thank you guys! Getting closer in that the error is gone and it is
running
> (some of) the scripts in the folder. In the folder c:\scripts I created
two
> test scripts:
> Script1.sql (Use Northwind select * from orders where orderID = 10317 )
> Script2.sql (Use Northwind select * from orders where employeeID = 5 )
> They are both just lookups for Northwind. Both of them run fine
> individually and return results, but when using the batch only one was
being
> returned (scripts2.sql). So, I tried swapping the names of the files to
see
> if only the 2nd one would run.. and this time the log showed that they
both
> ran.
> Here's what I used:
> --
> @.ECHO OFF
> IF "%1"=="" GOTO Syntax
> FOR %%f IN (%1\*.sql) DO osql -Usa -Ppasswordhere -Spryancompaq -i
> %%f -oC:\log.txt
> GOTO End
> :Syntax
> ECHO Please specify a folder like this:
> ECHO RunScripts c:\scripts
> ECHO to run all the SQL scripts in that folder
> :End
> ECHO.
> --
> Could it be that it is actually running both, but that it overwrites the
Log
> file after the first one? If so, I wonder why it displayed both results
the
> 2nd time. Perhaps the order of the scripts has something to do with it?
> (Of course, the order they are run is important in many cases... we
usually[vbcol=seagreen]
> name our scripts starting with 01script, 02script, etc.. I wonder if this
> batch would run them but that order.. will try some tests..)
>
>
>
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:uzoT5D5UEHA.412@.TK2MSFTNGP10.phx.gbl...
> then
look[vbcol=seagreen]
will[vbcol=seagreen]
scripts[vbcol=seagreen]
> issue
in
>

Monday, February 20, 2012

OS error 5 in PULL Subscription

I am getting the error:
The process could not read file
'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1\20050203112524\Table1.
sch' due to OS error 5. The step failed.
when trying to start a PULL subscription in SQL Server 7.0.
The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1' path has all
rights given to Everyone.
Any ideas?
-WillError 5 is Access denied. So check both, NTFS and Share permissions, ant try
to connect there using Agents account.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Will T" <unknown@.nowhere.net> wrote in message
news:O0cODFiCFHA.3280@.TK2MSFTNGP14.phx.gbl...
> I am getting the error:
> The process could not read file
>
'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1\20050203112524\Table1.
> sch' due to OS error 5. The step failed.
> when trying to start a PULL subscription in SQL Server 7.0.
> The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1' path has all
> rights given to Everyone.
> Any ideas?
> -Will
>|||I am connecting using the sa account on the Distributor. What NT account
would that be?
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in
message news:OmSaYNiCFHA.1392@.tk2msftngp13.phx.gbl...
> Error 5 is Access denied. So check both, NTFS and Share permissions, ant
try
> to connect there using Agents account.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> www.SolidQualityLearning.com
> "Will T" <unknown@.nowhere.net> wrote in message
> news:O0cODFiCFHA.3280@.TK2MSFTNGP14.phx.gbl...
> > I am getting the error:
> >
> > The process could not read file
> >
>
'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1\20050203112524\Table1.
> > sch' due to OS error 5. The step failed.
> >
> > when trying to start a PULL subscription in SQL Server 7.0.
> >
> > The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1' path has all
> > rights given to Everyone.
> >
> > Any ideas?
> >
> > -Will
> >
> >
>|||Is that a hidden public share or is it the admin share? It
looks like an admin share and if it's an administrative
share, the account needs to be an admin on the box to access
the share. Or you need to create a public share with the
appropriate rights, permissions.
-Sue
On Thu, 3 Feb 2005 13:50:40 -0500, "Will T"
<unknown@.nowhere.net> wrote:
>I am getting the error:
>The process could not read file
>'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1\20050203112524\Table1.
>sch' due to OS error 5. The step failed.
>when trying to start a PULL subscription in SQL Server 7.0.
>The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1' path has all
>rights given to Everyone.
>Any ideas?
>-Will
>|||Will,
Dejan is referring to the SQL Server Agent on your subscriber. That is a
service running as a domain user which should have the right to read files
from the distribution working folder. Log on to the subscriber using this
same account and try to read files from the DWF to double-check that rights
are set up correctly.
Rgds,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)|||Well spotted Sue,
- Will, typically you'd share \\MYSERVER\ReplData
Rgds,
Paul Ibison|||Thanks for the clarification. I will look in to it.
Thanks,
Will
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:uC$9qAjCFHA.3732@.TK2MSFTNGP14.phx.gbl...
> Will,
> Dejan is referring to the SQL Server Agent on your subscriber. That is a
> service running as a domain user which should have the right to read files
> from the distribution working folder. Log on to the subscriber using this
> same account and try to read files from the DWF to double-check that
rights
> are set up correctly.
> Rgds,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||The '\\MYSERVER\ReplData' is shared to Everyone. Thanks.
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:b505011s7n93vo5p6cd8v6hin7e6ho8013@.4ax.com...
> Is that a hidden public share or is it the admin share? It
> looks like an admin share and if it's an administrative
> share, the account needs to be an admin on the box to access
> the share. Or you need to create a public share with the
> appropriate rights, permissions.
> -Sue
> On Thu, 3 Feb 2005 13:50:40 -0500, "Will T"
> <unknown@.nowhere.net> wrote:
> >I am getting the error:
> >
> >The process could not read file
>'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1\20050203112524\Table1
.
> >sch' due to OS error 5. The step failed.
> >
> >when trying to start a PULL subscription in SQL Server 7.0.
> >
> >The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSERVER_PUB1_PUB1' path has all
> >rights given to Everyone.
> >
> >Any ideas?
> >
> >-Will
> >
>|||Thank you all for the information. The account on the local MSDE machine was
only a local account. I changed it to an account on the network and it now
works fine.
Q: is it standard practice to make an accoutn just for this type of thing?
-Will
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:uC$9qAjCFHA.3732@.TK2MSFTNGP14.phx.gbl...
> Will,
> Dejan is referring to the SQL Server Agent on your subscriber. That is a
> service running as a domain user which should have the right to read files
> from the distribution working folder. Log on to the subscriber using this
> same account and try to read files from the DWF to double-check that
rights
> are set up correctly.
> Rgds,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||If you need the SQL Server to access anything outside of its own process eg
mail, reporting services, replication, then a domain user is mandatory. We
tend to have a separate domain user account for each server, although we
have some non-trusted domains so this is mandatory. This account is a local
administrator, but not a domain admin. I have also seen places where the
same account is used for each sql server. In part I guess it depends on how
securely you guard your passwords - in the one-for-all scenario, if the
password is compromised, you lose control of all your servers.
HTH,
Paul Ibison (SQL Server MVP)

OS error 5 in PULL Subscription

I am getting the error:
The process could not read file
'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1\20050203112524\Table1.
sch' due to OS error 5. The step failed.
when trying to start a PULL subscription in SQL Server 7.0.
The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1' path has all
rights given to Everyone.
Any ideas?
-WillError 5 is Access denied. So check both, NTFS and Share permissions, ant try
to connect there using Agents account.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
"Will T" <unknown@.nowhere.net> wrote in message
news:O0cODFiCFHA.3280@.TK2MSFTNGP14.phx.gbl...
> I am getting the error:
> The process could not read file
>
'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1\20050203112524\Table1.
> sch' due to OS error 5. The step failed.
> when trying to start a PULL subscription in SQL Server 7.0.
> The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1' path has all
> rights given to Everyone.
> Any ideas?
> -Will
>|||I am connecting using the sa account on the Distributor. What NT account
would that be?
"Dejan Sarka" <dejan_please_reply_to_newsgroups.sarka@.avtenta.si> wrote in
message news:OmSaYNiCFHA.1392@.tk2msftngp13.phx.gbl...
> Error 5 is Access denied. So check both, NTFS and Share permissions, ant
try
> to connect there using Agents account.
> --
> Dejan Sarka, SQL Server MVP
> Associate Mentor
> www.SolidQualityLearning.com
> "Will T" <unknown@.nowhere.net> wrote in message
> news:O0cODFiCFHA.3280@.TK2MSFTNGP14.phx.gbl...
>
'\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1\20050203112524\Table1.
>|||Is that a hidden public share or is it the admin share? It
looks like an admin share and if it's an administrative
share, the account needs to be an admin on the box to access
the share. Or you need to create a public share with the
appropriate rights, permissions.
-Sue
On Thu, 3 Feb 2005 13:50:40 -0500, "Will T"
<unknown@.nowhere.net> wrote:

>I am getting the error:
>The process could not read file
> '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1\20050203112524\Table1
.
>sch' due to OS error 5. The step failed.
>when trying to start a PULL subscription in SQL Server 7.0.
>The '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1' path has all
>rights given to Everyone.
>Any ideas?
>-Will
>|||Will,
Dejan is referring to the SQL Server Agent on your subscriber. That is a
service running as a domain user which should have the right to read files
from the distribution working folder. Log on to the subscriber using this
same account and try to read files from the DWF to double-check that rights
are set up correctly.
Rgds,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)|||Well spotted Sue,
- Will, typically you'd share \\MYSERVER\ReplData
Rgds,
Paul Ibison|||Thanks for the clarification. I will look in to it.
Thanks,
Will
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:uC$9qAjCFHA.3732@.TK2MSFTNGP14.phx.gbl...
> Will,
> Dejan is referring to the SQL Server Agent on your subscriber. That is a
> service running as a domain user which should have the right to read files
> from the distribution working folder. Log on to the subscriber using this
> same account and try to read files from the DWF to double-check that
rights
> are set up correctly.
> Rgds,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||The '\\MYSERVER\ReplData' is shared to Everyone. Thanks.
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:b505011s7n93vo5p6cd8v6hin7e6ho8013@.
4ax.com...
> Is that a hidden public share or is it the admin share? It
> looks like an admin share and if it's an administrative
> share, the account needs to be an admin on the box to access
> the share. Or you need to create a public share with the
> appropriate rights, permissions.
> -Sue
> On Thu, 3 Feb 2005 13:50:40 -0500, "Will T"
> <unknown@.nowhere.net> wrote:
>
> '\\MYSERVER\D$\MSSQL7\ReplData\unc\MYSER
VER_PUB1_PUB1\20050203112524\Table1
.
>|||Thank you all for the information. The account on the local MSDE machine was
only a local account. I changed it to an account on the network and it now
works fine.
Q: is it standard practice to make an accoutn just for this type of thing?
-Will
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:uC$9qAjCFHA.3732@.TK2MSFTNGP14.phx.gbl...
> Will,
> Dejan is referring to the SQL Server Agent on your subscriber. That is a
> service running as a domain user which should have the right to read files
> from the distribution working folder. Log on to the subscriber using this
> same account and try to read files from the DWF to double-check that
rights
> are set up correctly.
> Rgds,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>|||If you need the SQL Server to access anything outside of its own process eg
mail, reporting services, replication, then a domain user is mandatory. We
tend to have a separate domain user account for each server, although we
have some non-trusted domains so this is mandatory. This account is a local
administrator, but not a domain admin. I have also seen places where the
same account is used for each sql server. In part I guess it depends on how
securely you guard your passwords - in the one-for-all scenario, if the
password is compromised, you lose control of all your servers.
HTH,
Paul Ibison (SQL Server MVP)