Showing posts with label opening. Show all posts
Showing posts with label opening. Show all posts

Sunday, March 25, 2012

default database for opening a .sql file?

I am using SQL Server Management Studio. Whenever I open a .sql file, it
does 2 annoying things:
1) prompts me to connect, yet again.
2) sets the database drop down to master again.
The second one, in particular, is really annoying. Is there a way to change
the database that it connects to when I open a .sql file?
Note: setting the default database for the server worked for windows created
with "New Query" but not for opening .sql files.
Heh, 2 seconds after posting I stumble across it. When it prompts me to
connect, there is an Options button. I clicked it and on the Connection
Properties tab it had the same "connect to database" dropdown that I used to
set the default for new query windows. Now whenever I open a .sql file it
goes to the right database.
"Adam J. Schaff" <aschaff@.cascodev.com> wrote in message
news:%23dCE6D4IHHA.4928@.TK2MSFTNGP06.phx.gbl...
>I am using SQL Server Management Studio. Whenever I open a .sql file, it
>does 2 annoying things:
> 1) prompts me to connect, yet again.
> 2) sets the database drop down to master again.
> The second one, in particular, is really annoying. Is there a way to
> change the database that it connects to when I open a .sql file?
> Note: setting the default database for the server worked for windows
> created with "New Query" but not for opening .sql files.
>
|||>I am using SQL Server Management Studio. Whenever I open a .sql file, it
>does 2 annoying things:
> 1) prompts me to connect, yet again.
SQL Server 2005 Service Pack 2 will fix this problem. We just released a
December CTP that has this improvement and many more.
http://www.microsoft.com/downloads/details.aspx?FamilyID=d2da6579-d49c-4b25-8f8a-79d14145500d&DisplayLang=en
Paul A. Mestemaker II
Program Manager
Microsoft SQL Server Manageability
http://blogs.msdn.com/sqlrem/
"Adam J. Schaff" <aschaff@.cascodev.com> wrote in message
news:%23dCE6D4IHHA.4928@.TK2MSFTNGP06.phx.gbl...
>I am using SQL Server Management Studio. Whenever I open a .sql file, it
>does 2 annoying things:
> 1) prompts me to connect, yet again.
> 2) sets the database drop down to master again.
> The second one, in particular, is really annoying. Is there a way to
> change the database that it connects to when I open a .sql file?
> Note: setting the default database for the server worked for windows
> created with "New Query" but not for opening .sql files.
>

Tuesday, February 14, 2012

Deallocating cursor if exception occured.

Hi all,
i am facing one problem while executing stored procedure.
What i am doing is i am opening one cursor and then depending on values
fetch inside the cursor i am inserting data into one table.
But sometimes my insert query failes due to violation in primary key.
In that case sp is not directly stopping its execution.
So my question is if such situation occured how will i deallocate my
cursor. I am using sql server 2000.
How to handle such exception to execute next part of stored procedure.
Thanks in advance.
trialproduct2004@.yahoo.com wrote:
> Hi all,
> i am facing one problem while executing stored procedure.
> What i am doing is i am opening one cursor and then depending on values
> fetch inside the cursor i am inserting data into one table.
>
I suggest you do that with a WHERE clause rather than a cursor.
INSERT INTO tbl1 (co1, col2, ...)
SELECT col1, col2, ...
FROM tbl2
WHERE ... ?

> But sometimes my insert query failes due to violation in primary key.
> In that case sp is not directly stopping its execution.
Ditto. Better to fix your code rather than handle the errors it causes.
Change your INSERT query to avoid inserting duplicate rows.
Cursors should be a last resort only. At least 99.9% of the time you
can and should avoid them.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx