Check if field is set in procedure: SQLAnywhere - sybase

is there a way to check, if a field in a table is set by a procedure in Sybase Anywhere v12?

If you have access to Sybase Central as DBA or as the procedure owner you can SQL for the procedure.
From the documentation:
Use the SQL Anywhere 12 plug-in to connect to the database as a user with DBA or Resource authority.
In the left pane, double-click Procedures & Functions.
Select the procedure.
Use one of the following methods to edit the procedure:
In the right pane, click the SQL tab.
Right-click the procedure and click Edit In New Window.

Related

Grant execute on all stored procedures using SSMS

I have created a user with database roles db_datareader, db_datawriter and public. Also I have configured with server roles as public.
Now this user cannot view the list of stored procedure when clicking on stored procedures node in objects explorer. How can I assign permission to see and execute all the stored procedures? I want to do this through SSMS without launching any command.
I am using SQL Server 2012 and below versions:
Microsoft SQL Server Management Studio 11.0.2100.60
Microsoft Data Access Components (MDAC) 10.0.17763.1
Microsoft MSXML 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 9.11.17763.0
Microsoft .NET Framework 4.0.30319.42000
Sistema operativo 6.3.17763
Looks like you can do this, though not as "simple" as you would expect.
I would, personally create a database role to do this. Go to your database in the Object explorer, and expand the Security Folder. Then right click Roles and Select New -> New Database Role.
Give the Role a name (I'll use db_executor) on the General Pane and then go to the Securables Pane. Click Search... at the top and select the radio option Specific Objects... and click OK. Click Object Types... and then tick Databases and then OK. Now click Browse... and tick the database you are adding the role to, then click OK and then OK.
In the datagrid at the bottom locate the Permission Execute, and tick the box in the column Grant. Then OK. This will run the below SQL on your instance:
USE [YourDatabase]
GO
CREATE ROLE [db_executor]
GO
use [YourDatabase]
GO
GRANT EXECUTE To [db_executor]
GO
Yes, Microsoft really is inconsistent with the casing of USE for that statement, and it omits the ; in it's commands.
Now you have created the role, locate the user you want to give access to in the object explorer in the Users folder. Right Click them and select Properties. Go to the Membership Pane and tick the box next to db_executor. Then click OK. This will run the below SQL on your instance:
USE [YourDatabase]
GO
ALTER ROLE [db_executor] ADD MEMBER [YourUser]
GO
Of course, why you wouldn't just run the 2 above commands, which is far quicker, I do not know.
I don't think there's a graphical way of doing this within the UI, but you can create a new query window in SSMS and execute one of these queries.
For a particular role you can:
/* GRANT EXECUTE TO THE ROLE */
GRANT EXECUTE TO role_what_needs_permissions
For a user
USE [the_database]
GO
GRANT EXECUTE TO [the_user]

SSRS 2012 Subscriptions - Credentials used to run this report are not stored

I'm trying to create a subscription on an SSRS 2012 report, working from a SQL Server 2008 database. From what I've read elsewhere, if I store the credentials in an individual report / stored datasource in the Report Manager, I should be able to create a subscription.
Unfortunately, for some reason this isn't happening for me. I have tried storing the credentials in a single reports, and also creating a datasource with stored credentials, with no luck (the 'Test Connection' button shows a successful connection). Please see screenshots.
Can anyone suggest what else I may still need to do to successfully create subscriptions?
Thanks,
Gavin
The problem you are having is that the credentials are not stored in the report itself. You will need to go into the report and right click on the data source and oull up properties then you will need to have a SQL Account that has rights to the data and then open the credentials tab and enter the username and passowrd in the blanks provided then be sure to click remember credentials then you should be able to set-up a subscription with no problem.
Since youa are using subscriptions the report itself needs a user name to runit as. WHat you are trying to do here is create a data source for the folder to use. But the data source being used by the report is a seperate connection.
I both embedded the data in the report as suggested by Wes Palmer (thanks) and used a specific SQL server account rather than integrated security. I then needed two further steps:
1.) Add a 'Report Server' entry into the msdb 'syscategories table as follows:
sp_configure 'allow update', 1
go
reconfigure with override
go
SET IDENTITY_INSERT syscategories ON
go
insert into syscategories(category_id, category_class, Category_type, Name) values(100, 1, 1, 'Report Server')
go
SET IDENTITY_INSERT syscategories OFF
go
exec sp_configure 'allow update', 0
go
reconfigure with override
go
2.) I set the SSRS Service account to a domain admin account.

Default schema for DROP and SELECT INTO in stored procedures

I am a bit confused as to how the default database schema is determined in MS SQL server.
I have the following stored procedure as a minimal working example:
CREATE PROCEDURE [dbo].[SampleSP]
AS
SELECT 'HI' as [SampleColumn]
INTO [SampleTable]
DROP TABLE [SampleTable]
All tests are executed using a user User on MS SQL server using Windows Auth with a default database schema of the same name.
When I execute this SP on MS SQL Server 2005 installation (running in compatibility mode 80, i.e. Server 2000) the table is created as [User].[SampleTable] and DROP TABLE fails with Invalid object name 'SampleTable' (I assume because it looks for [dbo].[SampleTable])
When I DROP TABLE [SampleTable] in a separate query it does work
When I execute the SP on MS SQL Server 2008 R2 (also running in compat. 80) the table is created as [dbo].[SampleTable] and dropped without error
I have found this answer describing the lookup in stored procedures, but it doesn't mention the user default in that context, even though it is used on 2005. Maybe someone knows how this changed and whether new versions can be configured to behave the same way.
It sounds like you just need to set the default schema for the user to dbo:
ALTER USER YourUser WITH DEFAULT_SCHEMA = dbo;
That way it's set at the user level and you won't need to alter any code.

Entity Framework update wizard only showing stored procedures in system folder

I created a stored procedure in sql server called dbo.GetDrugSetHistory
I tested the SP, works fine.
I went into my .edmx file and right clicked, then clicked "update Model from Database..."
I am unable to click the checkbox that says "Stored Procedures and Functions", the checkbox at the bottom that says "Import selected stored procedures and functions into the entity model" is greyed out and not selectable.
I then click on the "Refresh" tab, and then click to expand "Stored Procedures and Functions", below this I see one schema "dbo", when I click to expand "dbo", I only get the dbo procedures listed in the "System Stored Procedures" folder (i.e. fn_diagramobjects, sp_alterdiagram, etc.)
Does anyone know why I cannot see my newly created stored procedure? Is this a permissions issue?
here is a copy of the stored procedure, just in case...
ALTER PROCEDURE [dbo].[GetDrugSetHistory]
#ProfileID int
AS
BEGIN
SELECT distinct s.*
from Prescriptions p
LEFT JOIN Sets s ON p.SetID = s.SetID
where p.ProfileID = #ProfileID
END
OK, figured it out. It was a SQL Server permissions issue. Went into the user account properties and granted a bunch of permissions. The stored procedures now appear.

Automatically add GRANT EXECUTE to Drop&Create script in MSSQL Management Studio

There is a context menu in MSSQL - Script Stored Procedure as -> DROP and CREATE
But when I am generating procedure, it do not contain existing GRANT EXECUTE role.
How can I add (automatically!) it to generating script?
In SSMS, go to Tools, Options, SQL Server Object Explorer, Scripting and in the Object Scripting Options section, change Script Permissions to True.

Resources