Classic asp Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS - asp-classic

I use insert command to linked server such as
SET ANSI_NULLS ON
SET ANSI_WARNINGS ON
INSERT linked_server.dbname.dbo.table SELECT a,b,c, FROM my_table
This query It seems fine from smss, but when I run it through classic asp adodb.connection it return this
Description: [Microsoft][ODBC SQL Server Driver][SQL Server]Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.
Help context: 0
Help file:
Native error: 7405
Error number: -2147217900
Error source: Microsoft OLE DB Provider for ODBC Drivers
SQL state: 37000
How can I get the same result as in smss? Thanks

Related

Sql Server - Select Into Linked Server

I linked an oracle db to my sql server.
I need to create a same table as linked server on my local db.
I'm trying to execute SELECT INTO query but I taking an error.
SELECT * INTO ABC_SYSUSERS FROM [OfficeOracle]..[PROJECTA].[SYSUSERS]
This is my error message.
The OLE DB provider "ORAOLEDB.Oracle" for linked server "OfficeOracle"
supplied inconsistent metadata for a column. The column "USERNAME"
(compile-time ordinal 1) of object ""PROJECTA"."SYSUSERS"" was
reported to have a "DBCOLUMNFLAGS_ISFIXEDLENGTH" of 16 at compile time
and 0 at run time.
Any solution ?
Actually, I could not fix the error which I mention above but I fixed my problem with using OPENQUERY;
SELECT * FROM OPENQUERY(LinkedServerName, 'SELECT * FROM DBName.Schema.Table')

Invalid SQL Server Table Object

I have server with only two databases; in one database I have a table:
CREATE TABLE [dbo].[WR_Shipping](
[ShipmentID] [int] NOT NULL,
[OrderNumber] [int] NOT NULL,
[ShippedOn] [datetime] NULL,
[ShippingMethod] [nvarchar](100) NULL,
[ShippingTrackingNumber] [nvarchar](100) NULL,
[ShippedVIA] [nvarchar](100) NULL,
[TrackingURLAppConfig] [nvarchar](100) NULL,
[ShipmentNotes] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
I can read from the table when logged on the SQL Server Manager as an admin without issue. My web application logs on to the server with a different user ID. I've checked that that user ID has SELECT, UPDATE, INSERT, DELETE, and EXECUTE permission on the entire database. I've also check to make sure that the effective permissions for this table are correct for this user. I've even logged on to SSMS as the web application would and can execute SELECT * FROM WR_Shipping without issue. However, I can execute SELECT * FROM Product with no problem.
I've dropped and recreated the table several times. I have the same table running in my production database, and I can connect to it without issue using the same code.
I've tried every way I can think of naming the table: WR_Shipping, wr_shipping, dbo.WR_Shipping, [database].dbo.WR_Shipping. None of those work; all generate the same error. However, they all work just fine from the SQL Server Management Console. I can't even run something as simple as SELECT * FROM WR_Shipping from the web app.
The error I receive is System.Data.SqlClient.SqlException: Invalid object name 'WR_Shipping'. This error is throw when I try to execute SqlCommand.ExecuteReader. That command is in a routine that I use all over my web app. It takes in a string (the SQL) and a connection, and returns an IDataReader.
Update
I've tried everything that has been suggested here to no avail. Every query I tried works, even against other tables in the same database and schema. This one table never worked. I ended up cloning the production database and using that as my test database instead of continuing to work with this database. Previously I had just been committing the same changes to both databases (production and test).
First, verify the connection string stored in the application's config file is correct.
Assuming all looks good, try these two items:
In your code, set a breakpoint before your command's ExecuteReader (or similar). When you hit the breakpoint, drill into the Command's Connection property, and check the connection string being used. Make sure the connection string is the one you were expecting.
If that doesn't identify the issue, and if you have permissions to use SQL Profiler, set up a session to capture the traffic hitting the database with the application's userid. When you try your code, see what the actual SQL command is that is being sent, and debug from there.

Adding tempdb items on startup in SQL Server

How could I add some items to the tempdb anytime SQL Server starts up?
I'm no expert at this, but our ASP SessionState is stored in the DB and for some reason the tempdb items used for the session state get dropped anytime the server restarts. Not only do I need to recreate the items, but I also have to recreate the User mappings to tempdb. I have a script that does it, but I can't figure out how to run it on SQL startup
-- Use TempDB
use tempdb
go
-- Create Temp tables if they don't exist
IF NOT EXISTS(
SELECT 1 FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
AND TABLE_NAME = 'ASPStateTempSessions')
BEGIN
EXECUTE [ASPState].[dbo].[CreateTempTables]
END
-- If ASPSessionState user isn't mapped to temp db, map it
IF IS_MEMBER('ASPSessionState') IS NULL
create user ASPSessionState from login ASPSessionState
-- Give ASPSessionState user read/write permissions to tempdb
exec sp_addrolemember db_datareader, ASPSessionState
go
exec sp_addrolemember db_datawriter , ASPSessionState
go
Um, if you've used the standard settings to enable ASP.Net session state in tempdb, the system should have generated a stored proc (ASPState_Startup) as follows in the master database. This stored proc is configured to run automatically on SQL Server startup:
USE master
GO
DECLARE #sstype nvarchar(128)
SET #sstype = N'sstype_temp'
IF UPPER(#sstype) = 'SSTYPE_TEMP' BEGIN
DECLARE #cmd nchar(4000)
SET #cmd = N'
/* Create the startup procedure */
CREATE PROCEDURE dbo.ASPState_Startup
AS
EXECUTE ASPState.dbo.CreateTempTables
RETURN 0'
EXEC(#cmd)
EXECUTE sp_procoption #ProcName='dbo.ASPState_Startup', #OptionName='startup', #OptionValue='true'
END
So, the temp tables should be being recreated anyway, unless something has been altered since installing.
If additional permissions are required, I'd look to extending the existing CreateTempTables procedure in ASPState.
If this isn't working correctly, you might try using the aspnet_regsql command (found under %Windir%\Microsoft.Net\Framework\<framework version - to remove then re-add session state support to the server. You'd want to use -ssremove then -ssadd, but I'd suggest passing /? first to see all of the applicable options.

SQL Server service broker reporting as off when I have written a query to turn it on

I have made a small ASP.NET website. It uses sqlcachedependency
The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported. Please enable the Service Broker for this database if you wish to use notifications.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The SQL Server Service Broker for the current database is not enabled, and as a result query notifications are not supported. Please enable the Service Broker for this database if you wish to use notifications.
Source Error:
Line 12: System.Data.SqlClient.SqlDependency.Start(connString);
This is the erroneous line in my global.asax.
However, in sql server (2005), I enabled service broker like so (I connect and run the SQL Server service when I debug my site):
ALTER DATABASE mynewdatabase SET ENABLE_BROKER with rollback immediate
And this was successful.
What am I missing? I am trying to use sql caching dependency and have followed all procedures.
Thanks
I faced the same problem on one of our servers. this solved the issue (replace DBNAME with database name)
ALTER DATABASE DBNAME SET NEW_BROKER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE DBNAME SET ENABLE_BROKER;
Finally, check whether you get 1 for is_broker_enabled flag:
SELECT is_broker_enabled FROM sys.databases WHERE name = 'DBNAME'
Do you use a normal SQL instance, including Express, or are you using User Instances? ie. your connection string uses "AttachDbFilename" option? On user instances because the MDF is attached each time the instance is created, the Service Broker gets disabled each time because attach and restore operations always disable the broker in the database.
Ditch the "with rollback immediate" and try running the statement again.
Does it hang? If so kill any other sessions that are in the database and are blocking the session trying to alter the database.
Here's the script I mentioned in my comment.
use master
go
declare #parent int
declare #cmd varchar(100)
set #parent = 53
while exists (select * from sys.sysprocesses where spid = #parent and blocked <> 0)
begin
select #cmd = 'kill ' + cast(blocked as varchar(10))
from sys.sysprocesses
where spid = #parent
print #cmd
exec (#cmd)
end
You can change it by
Data Base - > Properties -> Options -> Service Broker

BizTalk Generate Metadata Fails with Stored Procedure

I am trying to set up the SQL Adapter in BizTalk 2009 to use a Stored Procedure in our SQL 2008 DB. For some reason, when I click "generate" in the wizard, and then click "next," I receive the following message:
Failed to execute SQL Statement. Please ensure that the supplied syntax is correct. New Transaction cannot enlist in the specified transaction coordinator.
I know the stored proc works, because we call it from C# code as well and I don't have a problem with it. I'm pretty sure I'm missing something basic, but I can't find what it is, and the only information I can find on using Stored Procs through the BizTalk SQL Adapter only show Select statements, so I don't know if there's some other setting I"m missing.
Here's the Stored Proc:
SET NOCOUNT ON;
Declare #Client int
set #Client = (Select Client_Id from Clients where Client_Name = #clientName)
Insert Into [FTP_Data].[dbo].[FileLog](Client_Id, Client_Name, FileType, Received)
Values(#Client, #clientName, #fileType, GETDATE());
Edit/Update: When I move the solution off my developer box and onto the actual server box, it works fine. As far as I can tell, the only difference is that the actual BizTalk Server components (instead of just the developer stuff) are on the same machine as the SQL Server to which I'm connecting. I would think that should be an issue, though...
"New Transaction cannot enlist in the specified transaction coordinator". Seems to indicate a possible DTC error. Is this the SQL server that the BizTalk databases are installed on?

Resources