How does db link opens once we close it with DBMS_SESSION.CLOSE_DATABASE_LINK? - oracle11gr2

I am going to include in my stored procedure "the command to close the database link" after the link has been used, however, my question is whether the database link opens automatically the next time the proc is used?
Or do we again need to include some command to open the database link at the beginning of the stored procedure?

Yes, a DB link gets opened automatically upon each use of the DB link.

Related

Export multiple stored procedures to text files

In SQL Server Management Studio, I have a database with 200 stored procedures. I'm exporting each stored procedure as a script, by right clicking -> script stored procedure -> CREATE To -> File.
Is it possible to export all procedures at once, using a powershell script or anything else?
Use the Generate Scripts tool in SSMS:
Right Click Database in Object Explorer.
Tasks -> Generate Scripts.
If given the "tutorial" click Next.
Select "Select specific database objects" and tick "Stored Procedures". Click Next.
Choose export method. Likely here you want "Save as script file" with "one script file per object" selected. Ensure you choose the export location.
Click Next and Finish buttons as required.
If you are using MGT for MSSQL, then you follow these steps.
open MGT MSSQL and connect and open the list of databases
right button the the database where the stored procs are, this will open the con menu
go to "Tasks"
select "Generate Scripts"
select specific object, in your case, select "Stored Procedures" (you can select all or as you need)
then press "Next"
at the "Set Scripting Options" form, select the option; if you want all selected procs in one file or not, choose the directory where you want your files to be generated.
press "Next"
at the "Summary" form press "Next"
at the "Save or Publish Scripts" Press finish..
DONE.
There are advance options at step 7. to create each procs with drop and create option or just create options. go through those if you need.
tc.
I have developed a C# application that can accomplish this, scripting out all tables, views, stored procedures, functions, etc. to text files (one per object). This is very useful for scripting out the objects on a regular basis then keeping track of them in a Git repository. Download the DB Schema Export Tool from https://github.com/PNNL-Comp-Mass-Spec/DB-Schema-Export-Tool/releases
Example command line for automation:
DB_Schema_Export_Tool.exe
C:\Cached_DBSchema
/Server:Proteinseqs
/DBList:Manager_Control,Protein_Sequences
/Sync:"F:\Projects\Database_Schema\DMS"
/Git /Commit
/L /LogDir:Logs
/Data:ProteinSeqs_Data_Tables.txt
On Linux, use mono DB_Schema_Export_Tool.exe
Information on Mono
There are other command line switches available; see the Readme.
In addition to SQL Server, the software supports Postgres. Example output files can be found at https://github.com/PNNL-Comp-Mass-Spec/DBSchema_DMS/tree/master/DMS_Pipeline

How to refresh OLE DB Destination Editor Table Selection

I'm in a standard SQL Server Integration Services Package. I have created a connection to my local db instance. I drop a data flow task and then using a OLE DB source and Destination, I start creating my expected simple data flow.
Problem: I create a new table to dump my data from the source in SSMS and go back to visual studio's and look for it in the OLE DB Destination -- Name of the Table or the view drop down menu option and it's not there.
How do I refresh the cache without needing to close the ENTIRE program and reopen it?
I've asked some colleagues and they say they just close the entire program and reopen. So, at my work, I'm not the only person having this problem.
What doesn't seem to work:
Tried to change connections in the drop down
Tried to delete the destination connection and recreate
Close the package and reopen
Close the solution and reopen
CTRL+SHIFT+R
What has worked:
Close the entire program, visual studios, and reopen
This hints to me that it's somehow cached in visual studios.
Is there a easier way? I feel like there has to be... this is just silly that I have to close the entire program each time I add a table ... I reject this reality and wish to create my own!
First of all check that you are not working in offline mode.
If you are not working offline, just try to change the selected connection manager from the drop down list and re-select the initial one, or just change the data access mode and re-select the initial one. I think this may force refreshing the tables in the list.

How can I save a new Stored Procedure to the database I'm working with in Server Explorer?

In Server Explorer (within Visual Studio) I can expand a database, right click on the Stored Procedures folder, and select "Add New Stored Procedure"
I can then add an SP and try to execute it. However, when I try to save the Stored Procedure (so that it will be subsequently available in the list of Stored Procedures for that database), it gives it the generic name "dbo.Procedure.sql*", even though I gave it another name, such as:
CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]
When the save dialog displays (wanting to save the .sql file to my Documents folder), I can rename it what I want, but it is not available in the list of Stored Procedures in the database.
How can I get it to be available there?
Note: If I right-click the Stored Procedure pane and select "copy path" (or some such), I do get what seems valid, namely:
MSSQL::/PROSQL42/PlatypusData/sa/SqlProcedure/dbo.Procedure.sql
But again, you see the generic "dbo.Procedure.sql" name. Yet no "dbo.Procedure.sql" displays in the list of Stored Procedures after saving, either.
So again, what do I need to do to save my new Stored Procedure into the database I'm working with?
CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]
and the definition that follows is the TSQL which will 'save' it to the database.
If you run that line again, you should get an error saying that it already exists.
To verify that it does, right-click the 'Stored Procedures' node and choose 'Refresh'.
If it doesn't appear in the database you think you're working with, check the connection of the window you're in.
To be sure, add
USE [DatabaseName]
GO
Before executing your CREATE PROCEDURE [dbo].[duckbilledPlatypiOfIowa]

Oracle DB: delete all the contents

I have oracle DB it is for testing purpose, I have not added any tables. I just want clear all the files like control, redo, archive, date. Ultimately I want fresh db. I know it can done by delete the db and recreate.
I have searched in the internet could not find any relevant information.
Update:
The reason for this requirement is, some of the above mentioned files are corrupted.
Please advice,
Thanks,
Ultimately I want fresh db
Then do the following:
Open DBCA
Select the operation "Delete Database", put the required credentials when asked.
After completion of step 2, go back to first step.
Select the operation "Create Database"

When I save SSIS package the changes are lost

I have a SQL Server 2005 SSIS package with an Execute SQL task. I edit the SQL statement, go through the OKs to make the change. I go back in to the Execute SQL task- and the changes have taken hold. Great.
I now go to save the package. I click save. I look back in the Execute SQL task, and the changes have been lost.
What is going on here and how can I stop it?
Click the Execute SQL Task
Click F4 to see the list of properties
Click the Expressions line and then the little [...] box to see the expressions
Change the expressions (or remove them if you don't want your name/sqlstatementsource/etc. to be set dynamically).
This is a nice feature for reusability and template based development of SSIS packages. We use it allt he time.
I had the same issue. The reason was that I used a config file with all the executables included, and sql code is just a property of one of the executable which is stored in the config file. When you change your code the config file does NOT get updated, but when you close/open your project the values are getting pulled from the config file which reverse your change to the initial state!
In order to fix this you need either to exclude your executable from the config file (what I did) or re-create the config file every time you change the package.
I hope this helps.
I found I was unable to change the "To" in the Send Mail Task. Or rather, I would press OK on the new value and then bring it up again and it would be the old value. What I did -- was to edit the dtsx file in Notepad by searching for the old value and changing it.

Resources