Linked Server failing on SQL Server job - sql

I have a linked server that perfectly works when executing a query. But when I place the query in a job, it fails.
Here is the setting of my linked server
Error

Read SQL Server Agent job fails when the job uses a linked server.
WORKAROUND To work around this problem, use one of the following
methods:
Method 1
Make the system administrator the owner of the job.
Method2:
Use mapped security context for the linked server and modify the job
to run as OSQL.
To set the mapped security context for the linked server: Right-click
the linked server, and then click Properties. Click the Security tab.
Select either of the following options. Be made using the login's
current security context Be made using this security context To modify
the job to run as OSQL: Right-click the job, and then click
Properties. In the Steps tab, click the Step Name that you want to
edit, and then click Edit. On the General tab of the Edit Job Step
dialog box, click Operating System Command (CmdExec) in the Type list.
In the Command text box, type osql –E –Q “Exec storedProcedure”. In the Edit
Job Step dialog box, click OK. In the Properties dialog box, click OK.
In linked server definition tick:
Be made using the login's current security context

I had this same issue, And after changing user permissions etc etc etc, I found this article and instead of using "Be made using the login's current security context" i used "Be made using this security context" and i specified the account and password which solved the issue. So the issue isnt with SQL jobs or my procedure it was in actual fact my linked server. Even though the link server did work... When calling a linked server within a SQL job the linked server had to have the account details specifically specified.

Related

Creating new user in SSMS with dialog box [duplicate]

I am running SQL Server Management Studio v17.6.
The online tutorials for creating a new Login show a dialog that comes up when your right-click on Logins and select New Login.
I don't see this dialog; instead I get a script to CREATE LOGIN which is OK but I would prefer the dialog.
I don't see an option to switch from getting a script to getting the dialog. I don't know if this version does not have the dialog or if I am just not finding the option.
Currently this is an Azure SQL limitation.
More information can be found here on azure.microsoft.com or here on Microsoft docs.
When creating a new login with the following SSMS menu item:
this is what appears with an Azure SQL database:
instead a dialog window appears when using a local database:
I also found a helpful post that explains the limitations at the time of this post.
Azure SQL limitations
What I did was inside SSMS, while connected to your Azure SQL instance, make sure you are first connected to the master database as shown:
Then run this script with your values against the master DB.
CREATE LOGIN WorldCitiesLogin
WITH PASSWORD = N'<your_password>'
GO
Next, switch your instance in SSMS to the database you want to map your login:
Then, run this script with your user name that maps to the newly created login above:
CREATE USER WorldCitiesUser
FOR LOGIN WorldCitiesLogin
WITH DEFAULT_SCHEMA = [dbo]
GO

VS LoadTest does not save results into the SQL Server

I am performing a Load Test using VS, but the results are not saved in SQL Server.
When I run the test, the table LoadTestRun is populated with data, but when the test is done, the table LoadTestTestSummaryData stays empty.
Let me know if you need more information.
Thank you
As pre-steps you need for Performance and Load Testing with Visual Studio:
install and configure Visual Studio ULTIMATE.
SQL Server (e.g SQLEXPRESS 2012) (both SERVER & MANAGER) e.g.
Be sure that SQLEXPRESS service is running. You can run SQL Server Configuration Manager and start it manually. Be careful for the correct INSTANCE_NAME. Also in Task Manager > Services. Next go to Start menu and find VS2012 Cross Tools Command Prompt. Type the following:
cd C:\ Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE
and
SQLCMD /S localhost\sqlexpress /i loadtestresultsrepository.sql
This will create Load test DB schema that is required for VS 2012 Load tests.
On the Load Test toolbar, choose Manage Test Controllers. The Manage Test Controllers dialog box is displayed.
In the Load Test Results Connection String, click the browse button (…) to display the Connection Properties dialog box.
Note
If you change the connection string for a controller, then you must select the controller.
In Server Name, type localhost\sqlexpress or the name of the server that you used in step 2 such as ContosoServer1.
Under Log on to the server, choose Use Windows Authentication.
Under Connect to a database, choose Select or enter a database name. Select LoadTest from the drop-down list box.
Choose OK.
All these steps has to be executed in order to get the proper level of integration between VS, SQL ( and maybe Excel for reporting). I suspect that
table LoadTestTestSummaryData stays empty.
because you are missing one of the above mentioned steps.
Could you get to database where you saved your result in, should be something in \sqlexpress in default? if only one table, there could be something wrong with Visual Studio. If you didn't get any table from load test, I would suggest you reset your follow this MSDN link and see what you may have missed:http://msdn.microsoft.com/en-us/library/ms318550.aspx

MS SQL: What is the easiest/nicest way to create a linked server with SSMS?

I am a beginner with SQL so I struggle with the MSDN description for creating a linked server in Management Studio.
I whant to link a SQL Server into another to use everything from ServerB on ServerA to e.g. provide one location other systems can connect to.
Both servers are in the same domain and both server have several databases inside.
When I start creating a linked server on ServerA in the general tap I select a name for the linked server and select SQL Server as Server type.
But I struggle on the Security tap. I have on both servers sa privilege so what is to set here?
Or which role should I take/crate for this connection?
My plan is to create views in a certain DB on ServerA with has also content of ServerB inside.
This views will be conusumed from an certain AD service user.
I already added this service user to the security on ServerA where the views are stored.
Do I also have to add this user somewhere on the linked ServerB?
I would recommend that you use Windows Authentication. Activate Security Delegation.
In the Security tab, choose "Add". Select your Windows user and check "Impersonate".
As a quick and dirty solution, you can choose "Be made using this security context" from the options list and enter a SQL Login which is valid on the remote server. Since quick and dirty solutions tend to last, i would strongly recommend to spend some time on impersonation.
In Server Objects => right click New Linked Server
2. The “New Linked Server” Dialog appears. (see below).
3. For “Server Type” make sure “Other Data Source” is selected. (The
SQL Server option will force you to specify the literal SQL Server
Name)
Type in a friendly name that describes your linked server (without spaces). – Select “Microsoft OLE DB Provider for SQL Server”
Product Name – type: SQLSERVER (with no spaces)
Datasource – type the actual server name, and instance name using this convention: SERVERNAMEINSTANCENAME
ProviderString – Blank
Catalog – Optional (If entered use the default database you will be using)
Prior to exiting, continue to the next section (defining security)
Click OK, and the new linked server is created
The easiest way would be to specify to make the connection using the current context, i.e. the user loging on to ServerA:
EXEC master.dbo.sp_addlinkedserver #server = N'ServerB', #srvproduct=N'SQL Server'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'ServerB',#useself=N'True',#locallogin=NULL,#rmtuser=NULL,#rmtpassword=NULL
This however assumes that users accessing the linked server connection have the correct privileges on ServerB (part 2 of your question) - otherwise you'd need to use impersonation as described by Martin K.

SQL Server Management Studio 2012 hangs

When I click on the "Databases" node in "Object Explorer" it just keeps on "Loading items" until at some point it just hangs.
This happens only when connecting to a remote server, not when accessing a database on my PC.
It also doesn't happen with any other node.
The guys at the web-hosting company didn't have any trouble with it. (But they're running 2008, and so is the SQL server there)
I reinstalled the whole SQL server etc. but to no avail.
What might be the problem?
I experienced this same problem: when accessing a remote server with the Object Explorer, SSMS would hang indefinitely. The Windows System Event Log would show DCOM error 10009 ("DCOM was unable to communicate with the computer MACHINE_NAME using any of the configured protocols.").
The solution was to clear the MRU history and other settings from my profile. To do that:
Close any open instances of SSMS 2012
In Explorer, open "%AppData%\Microsoft\SQL Server Management Studio"
Rename the "11.0" folder to something else, like "11.0.old"
Open SSMS 2012
You'll see that your MRU list has been cleared. You should then be able to re-enter your credentials and use SSMS as normal.
If everything works, you can delete the renamed folder. Otherwise, delete the new "11.0" folder that was created and rename the original one back to "11.0".
I have no idea whether it's actually the MRU list that's causing this problem or if it's some other profile data.
We were able to discover that SSMS is trying to make a DCOM connection over port 135 to the SQL Server (perhaps for SSIS, T-SQL Debugging, or something else). Our firewall was configured to block port 135. By opening the port in the firewall we were able to use SSMS (hence the reason it worked against local databases but not remote ones). Unfortunately, an open port 135 is an invitation for a lot of attacks, so that wasn't a practical solution for us.
Turn Auto-Close off on all the databases. Worked like a charm to me!
Every time you expand or refresh the database list, server has to awake the databases causing the hang.
Just run this to find all the databases that have auto-close on
SELECT name, is_auto_close_on
FROM master.sys.databases AS dtb
WHERE is_auto_close_on = 1
ORDER BY name
Credits to http://social.msdn.microsoft.com/Forums/sqlserver/en-US/99bbcb47-d4b5-4ec0-9e91-b1a23a655844/ssms-2012-extremely-slow-expanding-databases?forum=sqltools
To turn-off this setting for a database - Right click on database instance in object explorer -> Click properties -> Click "Options" in left navigation pane in database properties window -> Change the value of Auto Close property to "False" in right pane as shown in the snapshot below:
Assuming you have access to only one database at the hosting company (which is almost always the case, at least with a certain username/password), you can avoid the need to use the dropdown at all by setting your registered server to default to the database you're supposed to access:
(It may take longer here, too, but this will be one-time. You can also type it instead of waiting for the list to populate.)
This way, even if the login the host created for you routes you to tempdb or something by default, Management Studio will still put you in the context of your database.
I see now that you are talking about the Object Explorer node, not the "Use database" dropdown that I somehow interpreted incorrectly. An exercise to try might be to highlight the databases node (don't expand it) and click on F7 (Object Explorer Details). If this loads for you then it can be an alternative to navigate through the hierarchy and, as a bonus, you can show lots of entity attributes here and also multi-select, two things you have no control over in Object Explorer.
If that doesn't help, then your host should be helping you better than they appear to be. If SSMS 2012 is supported then they should be able to test this in SSMS 2012 and confirm or deny that they can reproduce it. If it is not supported then I think your recourse is to install SSMS 2008 as well (they can co-exist) and use it for managing this specific server.
Of course, just about anything that you can do in Object Explorer (and plenty of things you can't), you can do by using the catalog views and/or DMVs. So before you determine what to do, you may want to review (or share with us) exactly what you are using Object Explorer for - if there is a way to do it without Object Explorer, you might like the workaround better than having two versions of the tool (since the improvements in 2012 SSMS have absolutely nothing to do with Object Explorer).
In my case deleting the profile folder worked exactly once. The next time I opened SSMS 2012 it would freeze again when connecting to a server. SP1 didn't fix this either.
That was until I found the following simple workaround described on a ticket by Ben Amada over at connect.microsoft.com: Always close the Object Explorer Details before closing SSMS 2012.
So the complete workaround for me is this:
Follow Jaecen's answer, but close SSMS 2012 again after it created a clean profile folder
Apply Hoodlum's recommendation and copy SqlStudio.bin from the old profile folder to the new one (the old profile folder can be deleted afterwards)
Everytime before closing SSMS 2012 make sure the Object Explorer Details window is closed
The first two steps are required only once, or if the Object Explorer Details window was left open accidentally.
Edit
I just noticed that closing the Object Explorer Details window is also required when (re-)connecting to an SQL server in the same SSMS session. So basically whenever connecting to a server the Object Explorer Details windows has to be closed.
I spent over a month with Microsoft SQL Support troubleshooting this. It has been submitted as a bug.
I have both SQL 2012 SSMS and VS 2012 installed on Win 7 (64).
Deleting the profile folder never worked for any reasonable length of time.
The workaround we found was to ensure that my SSMS profile defaulted to the Master database when connecting. It appeared to have something to do with the fact that I'm connecting with Windows Authentication and I belong to more than one AD group that have SQL permissions assigned AND I don't have SQL specific permissions set up on my AD account.
I am connecting to several remote servers rangig from 2000 to 2012.
SMSS on local PC is SQL Server 2012,SMSS is 11.0.2100.60
SSMS freezes several times a day.When this occurs, I go via RDP to the
local server / SMSS / Activity Monitor and kill the processes from my PC with Database Name = master, one at a time, until SMSS on my PC unfreezes.
This always works, however, a cure for the disease raher than the symptoms would be highly welcome.
Have some SQL Servers from 2000 to 2012,
access then through SMSS from my desktop.
Problem occurs with varying frequency, looks like this: when I collapse a server in object explorer, SMSS freezes.
looking in activity monitor on the server in question, i find a process in master db with host = my desktop executing the following query
SELECT dtb.name AS [Name] FROM master.dbo.sysdatabases AS dtb ORDER BY [Name] ASC SMSS
killing the process frees SMSS.
Here is what worked for me
Open SSMS
click on connect to object explorer button
in the connect to server dialog box expand options >>
click reset all
Done!
I've test approximately all above answers but my SSMS got stuck in expanding the database list. I found the problem finally. The problem was because of a database that I restored it but It did restore correctly at the end. Then When I expanded the database list it was sticking.
I run a the query
SELECT
dtb.name AS [Name]
,dtb.database_id AS [ID]
,CAST(has_dbaccess(dtb.name) AS bit) AS [IsAccessible] FROM master.sys.databases AS dtb
Then the result took too long and at the end timed out but When I filter the stuck database I got result.
SELECT
dtb.name AS [Name]
,dtb.database_id AS [ID]
,CAST(has_dbaccess(dtb.name) AS bit) AS [IsAccessible] FROM
master.sys.databases AS dtb
Where name <> 'StuckDB' ORDER BY [Name] ASC
At the end I decided to detach StuckDB to solve my problem.
I have now applied SQL 2012 Service Pack 1 (through Windows Update) and it seems to work fine now, though it does take a very long time to load.
"Open SSMS click on connect to object explorer button in the connect to server dialog box expand options >> click reset all" - it works
I solved this problem by changing my default database back to master.
Go to database properties at SSMS and change compatibility to 2012. Then check.

Login Failed for user [sql server user]

I am new to SSRS and have deployed several reports. When I force windows authentication, everything works fine, but when I do this:
I am getting this error:
An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for dataset 'DataSet1'.
(rsErrorExecutingCommand) Login failed for user 'DWH_Reporting_User'.
I've configured the DWH_Reporting_User like this:
here are the details on DWH_Reporting_User for the ReportServer database:
here is the security on the server:
when i try to set security for that specific folder:
i am getting this error msg:
is there something obviously wrong with the way I've configured things?
The answer to this question was a series of comments. I went ahead and put it in the chat as well as an answer.
Go to the security of the server not the database and map the user to that database.
Can you recycle the application pool on the server where reporting services is running? Or reboot the IIS server if possible.
Another thing that comes to mind, when you launch this report it goes into the report server "Portal". Does this user have access to the actual report to view it? Click the details section of this "Portal" and assign this user as a content manager role.
DWH_REPORTING_USER is this an admin account on your domain?
Local admin on the server, so did you grant \COMPUTER_NAME\DWH_Reporting_User rights as a content manager in the roles section? Why dont you use a domain admin account?
So how do you access the actual report - that is your issue.
Do me a favor aprem, write up a stored procedure or sql query in the first tab of reporting services and run it using that user. Meaning in the shared data source it should be using this user DWH_Reporting_user. Test the connection then write a small sql statement to retrieve some data. Run the SQL script from within RS do you see any data?
#Aprem look at the three tabs at the top of rs, its the first tab to define datasets, this is where you can create an SQL query (and run it using the red exclamation mark). – JonH 20 mins ago
i defined a new dataset as "select top 1000 * from mytable", i rebuilt the project, deployed it, and now what do id o? – Артём Царионов 16 mins ago
In the "Shared Datasets" you have a dataset right? Double click on it and go to "Query Designer" it is a button on this form. Click on it and "Execute" the query (red exclamation mark). You dont need to deploy it right now, just do it on a test machine.ago
You specify the user in the datasource section "Shared Data Sources", that account is the account being used to "pull" the data. You really need to experiement with RS some more or read some material on it. This is as basic as it gets.
*Ok aprem do you understand your issue now, the user you are using to get the data has no issues, in addition, it is functioning correctly. Now you have to view the report. To view the report is to view the webpage, and to view a web page means you need to either use "Anon" access or windows authentication. So you need a domain or local WINDOWS account to view the report. This account needs to be setup on the RS portal as a content manager role. *
You are dealing with two beasts, one is the database (db server) and one is IIS (web server) each serve a specific purpose. The database serves to allow you to pull data while the web server hosts the pages.
The reportserver database is very important, it keeps a listing of all your reports and the meta data associated with your reports in the database. It also stores job ids and subscriptions associated with your reports. Basically it is the backend database for all reporting services stuff like reports, datasets, and datasources. Think of it this way when you create a new "Report Project" you are allowed to create reports, datasets, and datasources. Without the reportserver database how would the system remember your datasets, datasources, and report names? It is the heart of rs.
your data set is not used to connect to the reporting services databse, it is used to connect to the database you are getting the data to display on your report.
Does that user exist on the database the report is accessing?