Showing posts with label executed. Show all posts
Showing posts with label executed. Show all posts

Tuesday, March 27, 2012

Getting a .sql to execute another .sql

I would like to create a "parent" .sql file that when executed goes off and executes the contents a number of other "children" .sql files
Would anybody know how to do this
What happens if one of the .sql files fails? Will the others keep on running
ThankDepending on what you are trying to do, you might be able to use Xp_cmdshell
with OSQL. See BOL for details on both
--
Ray Higdon MCSE, MCDBA, CCNA
--
"lk1" <anonymous@.discussions.microsoft.com> wrote in message
news:A2CBAB73-B4EC-4852-A6D9-5DCE970A7282@.microsoft.com...
> I would like to create a "parent" .sql file that when executed goes off
and executes the contents a number of other "children" .sql files.
> Would anybody know how to do this?
> What happens if one of the .sql files fails? Will the others keep on
running?
> Thanks
>

Getting a .sql to execute another .sql

I would like to create a "parent" .sql file that when executed goes off and
executes the contents a number of other "children" .sql files.
Would anybody know how to do this?
What happens if one of the .sql files fails? Will the others keep on runnin
g?
ThanksDepending on what you are trying to do, you might be able to use Xp_cmdshell
with OSQL. See BOL for details on both
Ray Higdon MCSE, MCDBA, CCNA
--
"lk1" <anonymous@.discussions.microsoft.com> wrote in message
news:A2CBAB73-B4EC-4852-A6D9-5DCE970A7282@.microsoft.com...
> I would like to create a "parent" .sql file that when executed goes off
and executes the contents a number of other "children" .sql files.
> Would anybody know how to do this?
> What happens if one of the .sql files fails? Will the others keep on
running?
> Thanks
>

Monday, March 19, 2012

get value from SQL server 2005 select statement with datareader

I just want a simple datareader, that i can read the value returned from a select statement executed on a SQL server 2005 db.

The code below should work in, but email[calc]= rdr[0].ToString(); when i want to read some data a get a exception saying:

System.InvalidOperationException was unhandled by user code
Message="Invalid attempt to read when no data is present."
Source="System.Data"
StackTrace:
at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
at System.Data.SqlClient.SqlDataReader.get_Item(Int32 i)
at _Default.Login_Click(Object sender, EventArgs e) in d:\My Documents\Visual Studio 2005\WebSites\WebSite1\Default.aspx.cs:line 47
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

If anybody could advise me where my stupid mistake is then i would highly appreciate it!

SqlConnection conn = new SqlConnection(getConnection());
SqlDataReader rdr = null;

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "SELECT * FROM Customer";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;

try
{
conn.Open();

rdr = cmd.ExecuteReader();

int calc = 0;

Boolean login = false;
string[] email = new string[100];
object[] password = new object[100];

while (rdr.HasRows) // or rdr.Read();
{
rdr.Read();
email[calc]= rdr[0].ToString();
password[calc] = rdr["Password"].ToString();
if (UserName.Text.Equals(email[calc]) && Password.Text.Equals(password[calc]))
{
login = true;
}
calc++;
}

}
finally
{
rdr.Close();
}

thanks...

Try this:

if (rdr.HasRows)// or rdr.Read(); {while(rdr.Read()) { email[calc]= rdr[0].ToString(); password[calc] = rdr["Password"].ToString();if (UserName.Text.Equals(email[calc]) && Password.Text.Equals(password[calc])) { login =true; } calc++; } }
Hope this helps.

Sunday, February 26, 2012

Get script filename within SQL script

Hi,
SQL Server 2000. How do I get the filename of the script currently being
executed from within the .SQL script itself?
Is there a special variable containing the filename of the .SQL script, or
another method of obtaining it?
thanksHi
I am not quite sure what you are wanting, but the filename is really only
known by the application and AFAIK will not get passed to the server. If you
are running the command from a command line or batch file you could use
command prompt variables to substitute into a script something that is sent
to the server.
If you expand and post some example of what you are trying to do it may help!
John
"JJ Williams" wrote:
> Hi,
> SQL Server 2000. How do I get the filename of the script currently being
> executed from within the .SQL script itself?
> Is there a special variable containing the filename of the .SQL script, or
> another method of obtaining it?
> thanks
>
>|||Hi, thanks for your reply. Here's a simple example. test.sql contains:
print 'Script: test.sql'
select @.@.version
Execute it using osql:
> osql -U sa -i test.sql
Instead of hardcoding the script filename within the script, I want to get
the script filename programmatically within the script itself, e.g. via SQL
statement/command or otherwise. I've got dozens of .sql scripts and want a
general method to output the filename of the script (it doesn't matter if
the filename printed includes the whole folder path or not) and would rather
not hardcode the print statement in each script.
Hope that clarifies what I want to do.
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:7D7CA363-E705-4180-A8C5-18563818251B@.microsoft.com...
> Hi
> I am not quite sure what you are wanting, but the filename is really only
> known by the application and AFAIK will not get passed to the server. If
> you
> are running the command from a command line or batch file you could use
> command prompt variables to substitute into a script something that is
> sent
> to the server.
> If you expand and post some example of what you are trying to do it may
> help!
> John
> "JJ Williams" wrote:
>> Hi,
>> SQL Server 2000. How do I get the filename of the script currently being
>> executed from within the .SQL script itself?
>> Is there a special variable containing the filename of the .SQL script,
>> or
>> another method of obtaining it?
>> thanks
>>|||The origin of a batch is beyond the knowledge of the sql server engine that
executes it (which is where tsql code is interpreted and converted into
executable statements). This functionality would have to be something
implemented within the client application (osql in your example). The
execution of sql scripts isn't that difficult a task - you could write your
own application to do this - or perhaps wrap an application around osql -
you didn't indicate how you wanted to use this information.|||Hi
If you had two files script.sql and sript1.sql you could do something like:
script.sql
PRINT 'Script Script1.sql'
:r Script1.sql
script1.sql
SELECT @.@.VERSION
Then run script.sql
osql -E -S (local) -d master -n -i script.sql -o script.out
If you want to do this for multiple files you could create the file and then
run it something like:
del script.sqf script.out && (for %i in (*.sql) do echo PRINT 'Script %i' >>
script.sqf &&echo :r %i >> script.sqf) && osql -E -S (local) -d Master -n -i
script.sqf > script.out
If you have a large number of scripts it may be useful to limit how many are
run at any one given time.
John
"JJ Williams" wrote:
> Hi, thanks for your reply. Here's a simple example. test.sql contains:
> print 'Script: test.sql'
> select @.@.version
>
> Execute it using osql:
> > osql -U sa -i test.sql
>
> Instead of hardcoding the script filename within the script, I want to get
> the script filename programmatically within the script itself, e.g. via SQL
> statement/command or otherwise. I've got dozens of .sql scripts and want a
> general method to output the filename of the script (it doesn't matter if
> the filename printed includes the whole folder path or not) and would rather
> not hardcode the print statement in each script.
> Hope that clarifies what I want to do.
> "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> news:7D7CA363-E705-4180-A8C5-18563818251B@.microsoft.com...
> > Hi
> >
> > I am not quite sure what you are wanting, but the filename is really only
> > known by the application and AFAIK will not get passed to the server. If
> > you
> > are running the command from a command line or batch file you could use
> > command prompt variables to substitute into a script something that is
> > sent
> > to the server.
> >
> > If you expand and post some example of what you are trying to do it may
> > help!
> >
> > John
> >
> > "JJ Williams" wrote:
> >
> >> Hi,
> >>
> >> SQL Server 2000. How do I get the filename of the script currently being
> >> executed from within the .SQL script itself?
> >>
> >> Is there a special variable containing the filename of the .SQL script,
> >> or
> >> another method of obtaining it?
> >>
> >> thanks
> >>
> >>
> >>
>
>|||Hi
If you don't want to use the command prompt you may want to look at DMO to
do this.
John
"John Bell" wrote:
> Hi
> If you had two files script.sql and sript1.sql you could do something like:
> script.sql
> PRINT 'Script Script1.sql'
> :r Script1.sql
> script1.sql
> SELECT @.@.VERSION
> Then run script.sql
> osql -E -S (local) -d master -n -i script.sql -o script.out
> If you want to do this for multiple files you could create the file and then
> run it something like:
> del script.sqf script.out && (for %i in (*.sql) do echo PRINT 'Script %i' >>
> script.sqf &&echo :r %i >> script.sqf) && osql -E -S (local) -d Master -n -i
> script.sqf > script.out
> If you have a large number of scripts it may be useful to limit how many are
> run at any one given time.
> John
>
> "JJ Williams" wrote:
> > Hi, thanks for your reply. Here's a simple example. test.sql contains:
> >
> > print 'Script: test.sql'
> > select @.@.version
> >
> >
> > Execute it using osql:
> >
> > > osql -U sa -i test.sql
> >
> >
> > Instead of hardcoding the script filename within the script, I want to get
> > the script filename programmatically within the script itself, e.g. via SQL
> > statement/command or otherwise. I've got dozens of .sql scripts and want a
> > general method to output the filename of the script (it doesn't matter if
> > the filename printed includes the whole folder path or not) and would rather
> > not hardcode the print statement in each script.
> >
> > Hope that clarifies what I want to do.
> >
> > "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
> > news:7D7CA363-E705-4180-A8C5-18563818251B@.microsoft.com...
> > > Hi
> > >
> > > I am not quite sure what you are wanting, but the filename is really only
> > > known by the application and AFAIK will not get passed to the server. If
> > > you
> > > are running the command from a command line or batch file you could use
> > > command prompt variables to substitute into a script something that is
> > > sent
> > > to the server.
> > >
> > > If you expand and post some example of what you are trying to do it may
> > > help!
> > >
> > > John
> > >
> > > "JJ Williams" wrote:
> > >
> > >> Hi,
> > >>
> > >> SQL Server 2000. How do I get the filename of the script currently being
> > >> executed from within the .SQL script itself?
> > >>
> > >> Is there a special variable containing the filename of the .SQL script,
> > >> or
> > >> another method of obtaining it?
> > >>
> > >> thanks
> > >>
> > >>
> > >>
> >
> >
> >|||"Scott Morris" <bogus@.bogus.com> wrote in message
news:OrWEkAc$GHA.4808@.TK2MSFTNGP03.phx.gbl...
> The origin of a batch is beyond the knowledge of the sql server engine
> that executes it (which is where tsql code is interpreted and converted
> into executable statements). This functionality would have to be
> something implemented within the client application (osql in your
> example). The execution of sql scripts isn't that difficult a task - you
> could write your own application to do this - or perhaps wrap an
> application around osql - you didn't indicate how you wanted to use this
> information.
> you didn't indicate how you wanted to use this information.
I just want to log the filename along with the script contents and results
to an output file as the script executes. I have multiple scripts running
in sequence from separate osql command lines, all outputting to the same
file and I want to be able to see within the file which script did which
bit.
I think I'll stick with the simple hardcoded method.
thanks,|||OK thanks again for your reply.
I'll stick with hardcoding the filename in a PRINT statement within each
script.
"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:2A3737FA-C8B3-44DD-94EA-D0AFA16E02AC@.microsoft.com...
> Hi
> If you don't want to use the command prompt you may want to look at DMO to
> do this.
> John
> "John Bell" wrote:
>> Hi
>> If you had two files script.sql and sript1.sql you could do something
>> like:
>> script.sql
>> PRINT 'Script Script1.sql'
>> :r Script1.sql
>> script1.sql
>> SELECT @.@.VERSION
>> Then run script.sql
>> osql -E -S (local) -d master -n -i script.sql -o script.out
>> If you want to do this for multiple files you could create the file and
>> then
>> run it something like:
>> del script.sqf script.out && (for %i in (*.sql) do echo PRINT 'Script %i'
>> >>
>> script.sqf &&echo :r %i >> script.sqf) && osql -E -S (local) -d
>> Master -n -i
>> script.sqf > script.out
>> If you have a large number of scripts it may be useful to limit how many
>> are
>> run at any one given time.
>> John
>>
>> "JJ Williams" wrote:
>> > Hi, thanks for your reply. Here's a simple example. test.sql
>> > contains:
>> >
>> > print 'Script: test.sql'
>> > select @.@.version
>> >
>> >
>> > Execute it using osql:
>> >
>> > > osql -U sa -i test.sql
>> >
>> >
>> > Instead of hardcoding the script filename within the script, I want to
>> > get
>> > the script filename programmatically within the script itself, e.g. via
>> > SQL
>> > statement/command or otherwise. I've got dozens of .sql scripts and
>> > want a
>> > general method to output the filename of the script (it doesn't matter
>> > if
>> > the filename printed includes the whole folder path or not) and would
>> > rather
>> > not hardcode the print statement in each script.
>> >
>> > Hope that clarifies what I want to do.
>> >
>> > "John Bell" <jbellnewsposts@.hotmail.com> wrote in message
>> > news:7D7CA363-E705-4180-A8C5-18563818251B@.microsoft.com...
>> > > Hi
>> > >
>> > > I am not quite sure what you are wanting, but the filename is really
>> > > only
>> > > known by the application and AFAIK will not get passed to the server.
>> > > If
>> > > you
>> > > are running the command from a command line or batch file you could
>> > > use
>> > > command prompt variables to substitute into a script something that
>> > > is
>> > > sent
>> > > to the server.
>> > >
>> > > If you expand and post some example of what you are trying to do it
>> > > may
>> > > help!
>> > >
>> > > John
>> > >
>> > > "JJ Williams" wrote:
>> > >
>> > >> Hi,
>> > >>
>> > >> SQL Server 2000. How do I get the filename of the script currently
>> > >> being
>> > >> executed from within the .SQL script itself?
>> > >>
>> > >> Is there a special variable containing the filename of the .SQL
>> > >> script,
>> > >> or
>> > >> another method of obtaining it?
>> > >>
>> > >> thanks
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >

Sunday, February 19, 2012

Get message : The query cannot be excuted because some files are missing...

Hi

I can't work with my sql server 2000,
When I try to open a table I get the message:
"The query cannot be executed because some files are missing or not registered.

run setup again to make sure the required files are registered.

I uninstall and install again (few time)
But all the time i get this message.

Does any one know who to fix it??

Thanks
Efrat"Efrat" <shachare@.bgumail.bgu.ac.il> wrote in message
news:bcb64ccd.0405110145.62ff7855@.posting.google.c om...
> Hi
> I can't work with my sql server 2000,
> When I try to open a table I get the message:
> "The query cannot be executed because some files are missing or not
registered.
> run setup again to make sure the required files are registered.
> I uninstall and install again (few time)
> But all the time i get this message.
> Does any one know who to fix it??
> Thanks
> Efrat

Perhaps this applies?

http://support.microsoft.com/defaul...kb;en-us;315868

Simon