'OBJECT_SCHEMA_NAME' is not a recognized built-in function name - sql-server-2008-r2

I'm trying to run a script to set up tsqlt on SQL server 2008 r2 and getting this error
'OBJECT_SCHEMA_NAME' is not a recognized built-in function name.
on another machine with SQL 2008 r2, the script runs fine.
I can't see any difference in the users or permissions in the sql server setup for each respective machine.
this is the statement that throws the error:
CREATE FUNCTION tSQLt.Private_GetOriginalTableInfo(#TableObjectId INT)
RETURNS TABLE
AS
RETURN SELECT CAST(value AS NVARCHAR(4000)) OrgTableName,
OBJECT_ID(QUOTENAME(OBJECT_SCHEMA_NAME(#TableObjectId))
+ '.' + QUOTENAME(CAST(value AS NVARCHAR(4000)))) OrgTableObjectId
FROM sys.extended_properties
WHERE class_desc = 'OBJECT_OR_COLUMN'
AND major_id = #TableObjectId
AND minor_id = 0
AND name = 'tSQLt.FakeTable_OrgTableName';
GO

If this is in fact on SQL Server 2008 R2, your database is in SQL Server 2000 compatibility mode. You can tell what mode you're in now:
SELECT name, compatibility_level
FROM sys.databases
WHERE name = N'your_database';
If this is 80 you will need to move up (but this will require testing):
ALTER DATABASE your_database SET COMPATIBILITY_LEVEL = 100;
If you can't move up, then you can always get the schema name by joining to sys.schemas instead of relying on the built-in function.
That said, if you are on SQL Server 2005 RTM (as implied in a comment), OBJECT_SCHEMA_NAME was introduced in SQL Server 2005 Service Pack 2. You should not be running any system on SQL Server 2005 RTM anymore. Go install SP4 and you will be able to use this function.

Related

How to create DB2 connection from Dynamics AX 2012

In AX2012, I would like to create from x++ (in Dynamics) a query to DB2.
In my Server I installed the
Microsoft OLE DB Provider for DB2 Version 6.0
Which class have I to use by x++ to create and run the script in order to query the database?
I would like use this code, is right way?
System.Data.SqlClient.SqlCommand cmd;
System.Data.SqlClient.SqlParameterCollection parameters;
Int recCount;
Thanks.

Verify if SNAPSHOT isolation level is on in SQL Server 2008 R2

What SQL will I execute in SSMS for SQL Server 2008 R2 to know if SNAPSHOT isolation level is turned on in the database?
SELECT snapshot_isolation_state_desc from sys.databases
where name='<your database name here>'
will allow you to check if it is turned on or not.

passing parameter value through pgoledb to postgresql stored function

I am attempting to migrate a legacy client-server GIS application from Microsoft SQL Server to PostgreSQL. In this system the SQL Server database contains a large set of T-SQL stored procedures, each being an SQL Select query with one or more parameters.
In response to a client request, the server program – classic ASP VBScript – uses Microsoft ADODB to fill in the parameters values, execute the requested query and return the result set as an XML document to the client.
In the preliminary phase of the migration I have successfully:
installed PostgreSQL 9.3 for Windows, PgOleDB 1.0.0.20 and psqlODBC on a 32.bit Windows 7 Pro development PC
migrated the SQL Server database table definitions and constraint to a new PostgreSQL database and populated the tables using psqlODBC
using pgAdmin III, created and executed test queries against the PostgreSQL database
using pgAdmin III, created two test PostgreSQL table-valued Select functions – test1() one with no parameters and test2(text) with a single IN parameter — and verified that both execute correctly
written a test ASP/VBscript program that uses ADODB.Connection and ADODB.Command to connect to the PostgreSQL database, execute test1() - the no-parameter stored function - and create an ADODB.Recordset. This test works correctly.
However when I change my test ASP/VBscript program to use test2() and use objCmd.Parameters.Append like this:
objCmd.CommandText = "test2"
objCmd.Parameters.Append objCmd.CreateParameter("p1", adVarChar, adParamInput, 15, "000007-01012013")
to specify the required IN parameter, I get the ASP runtime error:
PgOleDB error '80004005' “Procedure name for automatic arguments is not unique“
Q1. What does the diagnostic “Procedure name for automatic arguments is not unique” mean?
Q2. Is there any public documentation available for PgOleDB other than the README.TXT and RELEASENOTES.TXT files installed along with PgOleDB.dll?

SQL Linked Server Update Openquery syntax error

I am trying to update data in a PervasiveSQL backend (Sage ERP system) from SQL Server 2008 R2 via a Linked Server setup. Below are details and error msg returned... The kicker is that the update statement works on a development box just fine, very similar setup. Any help will be GREATLY appreciated!
Environment:
Windows Server 2008 Enterprise (Cloud server, Rackspace)
Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86) Express Edition with Advanced Services on Windows NT 6.1 (Build 7601: Service Pack 1) (WOW64) (Hypervisor)
Sage Timberline ERP running with Pervasive SQL v.10 backend
Setup:
We have a LINKED SERVER setup in SQL Server 2008, using a 32-bit Timberline Driver (OBDC)
Linked server is using a MSDASQL provider with the following two properties set to TRUE, “Allow inprocess” and “Non Transacted Updates”
Issue:
We can successfully pull data, see query below, from linked server. We can successfully browse objects via the linked server in SSMS.
SELECT *
FROM OPENQUERY (TLLINKSERVER, 'SELECT * FROM TABLE1 where JOBID = ''00-00-111111''')
However the UPDATE statement below returns the following error.
UPDATE OPENQUERY(TLLINKSERVER, 'SELECT * FROM TABLE1 WHERE JOBID = ''00-00-111111''')
SET DATEFIELD = '2013-07-15'
Error:
OLE DB provider "MSDASQL" for linked server "TLLINKSERVER" returned
message "[Sage Timberline Office][Sage Timberline Office ODBC
Driver]Syntax Error.". OLE DB provider "MSDASQL" for linked server
"TLLINKSERVER" returned message "[Sage Timberline Office][Sage
Timberline Office ODBC Driver]UPDATE "\SERVER1\Company
Data\DATA\COMPANY1\"<< ??? >>."TABLE1" SET "DATEFIELD1"=? WHERE
"JOBID"=? AND "DATEFIELD1"=?".
Msg 7343, Level 16, State 4, Line 1
The OLE DB provider "MSDASQL" for linked server "TLLINKSERVER" could not
UPDATE table "[MSDASQL]".
Why not make things easier? Does PervasiveSQL not support direct updates via a linked server?
UPDATE TLLINKSERVER...TABLE1
SET DATEFIELD = '2013-07-15'
WHERE JOBID = '00-00-111111';
Or maybe:
SELECT * FROM OPENQUERY(TLLINKSERVER, 'UPDATE TABLE1
SET DATEFIELD = ''2013-07-15''
WHERE JOBID = ''00-00-111111'');
While the UPDATE OPENQUERY syntax you're using is supported for SQL Server linked servers, I'm not sure that's true for other platforms such as PervasiveSQL...
This is how I update table sin Oracle from SSMS.
The Linked server name in this case is MyLinkedServer.
I am updating the column CONTACT_EMAIL to MyEmail#MyDomain.COM where the STATE is one of the following (KY,OH,NY,PA,VA,DC):
UPDATE L
SET L.CONTACT_EMAIL ='MyEmail#MyDomain.COM'
FROM OPENQUERY(MyLinkedServer, 'SELECT * from MyTable')L
WHERE L.STATE IN('KY','OH', 'NY','PA','VA','DC')
OPENQUERY method works perfectly.

Creating a user without an associated login is not supported in SQL Server 2008 R2

When scripting a SQL Server 2000 database, on an SQL Server 2000 version of SQL Server, with SQL Server Management Studio 2008 R2 (10.50.1617.0) i get the error:
Creating a user without an associated login is not supported in SQL Server 2008 R2.
With the full stack trace:
Microsoft.SqlServer.Management.Smo.SmoException: Creating a user without an associated login is not supported in SQL Server 2008 R2.;
at Microsoft.SqlServer.Management.SqlScriptPublish.GeneratePublishPage.worker_DoWork(Object sender, DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)
at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
What is a good way to resolve this issue.
i've considered:
creating a login (and incur the wrath high atop the thing)
deleting the user (and incur the wrath from high atop the place)
select some rather than all objects to script, and don't script the user that offends SQL Server 2008 R2
But i'll let people on SO post answers, get answers upvoted, and accept an answer that best solves the problem.
As instructed. Just don't script the database users that have no associated login. You can do this in the Tasks > Generate Scripts wizard (pointing 2008 or later SSMS at your 2000 instance) by choosing to select specific database objects and unchecking any troublesome users:
I suspect that your SQL Server 2000 database has user aliases: these were required in SQL Server 6.5 in some circumstances because it was, er, crap,
Note what MSDN says:
sp_addalias is provided for backward compatibility. Microsoft® SQL Server™ version 7.0 provides roles and the ability to grant permissions to roles as an alternative to using aliases.
Run sp_helpuser on the SQL Server 2000 box and review the output and remove them