.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

Scope_Identity() always returns 0 and not the Identity in SQLServer 2008

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :Sql Server
 

I have a Stored Proceedure which DID return the Scope_Identity when this was executed in SQLServer 2000.

Now I am porting this over to SQLServer 2008, and this always returns 0, and not the Scope_Identity which it should. 

Here is the Stored Proceedure which will pass null for the parameter @pProjId for an insert:

CREATE proc dbo.hip_InsUpdProj
(
@pProjId	     int,
@pProjName	varchar(255),
@pProjDesc	varchar(1000),
@pProjNotes	varchar(8000),
@pProjDate	datetime,
@pProjType	int
)
as 

declare
	@RC	int,
	@ROWS	int
begin

if @pProjId = null
	begin
	insert into hip_Project (ProjectName, ProjectDesc, ProjectNotes, dtCreated)
	values (@pProjName, @pProjDesc, @pProjNotes, @pProjDate)
	 

View Complete Post


More Related Resource Links

Scope_Identity() always returns 0 and not the Identity

  

I have a Stored Proceedure which DID return the Scope_Identity when this was executed in SQLServer 2000.

Now I am porting this over to SQLServer 2008, and this always returns 0, and not the Scope_Identity which it should. 

Here is the Stored Proceedure which will pass null for the parameter @pProjId for an insert:

CREATE proc dbo.hip_InsUpdProj
(
@pProjId	int,
@pProjName	varchar(255),
@pProjDesc	varchar(1000),
@pProjNotes	varchar(8000),
@pProjDate	datetime,
@pProjType	int
)
as 

declare
	@RC	int,
	@ROWS	int
begin

if @pProjId = null
	begin
	insert into hip_Project (ProjectName, ProjectDesc, ProjectNotes, dtCreated)
	values (@pProjName, @pProjDesc, @pProjNotes, @pProjDate)
	end
else
	begin
	update hip_Project
	set ProjectName = @pProjName,
		ProjectDesc = @pProjDesc,
		ProjectNotes = @pProjNotes,
		dtCreated = @pProjDate,
		deleted = @pProjType
	where Project_Id = @pProjId
	end

select @RC = @@error
if @RC <> 0
	return @RC
end

--print SCOPE_IDENTITY()

if @pProjId = null
	SELECT SCOPE_IDENTITY() as newProjectID
else
	SELECT @pProjId as newProjectID
return 0

GO


Here is the script which creates the hip_Project Table:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[hip_Project](
	[Project_Id] [int] IDENTITY(200,1) NOT NULL,
	[ProjectName] [nvarchar](

SQLServer 2008 Tools and SQL 2005 Cluster

  
I recently built a SQL Server 2005 cluster on the o/s Windows Server 2008 R2.  I have been attempting to connect to the cluster from my Windows 7 dekstop with my SQL Server 2008 Tool set.  I have been unable to attach to this cluster since its creation. The firewall is temp off, remote connections in the surface area configuration is set to pipes and tcp/ip and the Browser surface is up and running. I ran Wireshark against the cluster and I could see that there was UDP conversations for ms-sql-m (SQL Port) but that was as far as it would get.  I am using a named instance so not using 1433, but I do see the cluster offering up high RPC ports but the client never responds after the initial UDP response. When I noticed that there was a two way conversation taking place, I went to a seperate machine and fired up SQL Server 2005 Tools and I was easily able to attach to the cluster.  So my question is - Are there any known incompatibilities between SQL Server 2005 cluster services and SQL Server 2008 Tool set?  I can use my 2008 tools to attach to a non-clustered SQL Server 2005 w/o issue.   Error when attempting to connect: A network-related or instance-specific error occured while establishing a connection to sql server.  The server was not found or was not accessible.  Verify that the instance name is correct and the SQL Server is con

Not able to install SqlServer 2008 says Restart computer failed

  
While trying to install SqlServer2008 it show Restart computer as failed. I have restarted my computer and still it shows the same error. Cant proceed further. Please advice on how to proceed to install SqlServer 2008.   Thanks Ashok

sql server 2008 - sqlserver(mssqlserver) services can't start

  
Sorry i need help, i have instal and reinstal sql 2008 over and over but always failed the problem is the services can't start and when i cek error log this written: http%3a%2f%2fgo.microsoft.com%2ffwlink%3fLinkId%3d20476%26ProdName%3dMicrosoft%2bSQL%2bServer%26EvtSrc%3dsetup.rll%26EvtID%3d50000%26ProdVer%3d10.0.1600.22%26EvtType%3d0xE53883A0%400xBE03358B%401306%4024

AdomdDataAdapter.Fill returns memory error when querying an SSAS Cube(2008)

  
For certain SQL's I will get the following error when calling the Fill method on an AdomdDataAdapter object. "Memory error: While attempting to store a string, a string was found that was larger than the page size selected. The operation cannot be completed."   Snippet of Code: DataSet ds1 = new DataSet(); AdomdCommand acmd1 = cn1.CreateCommand(); acmd1.CommandText = "SELECT ..."; AdomdDataAdapter ad1 = new AdomdDataAdapter(acmd1); ad1.Fill(ds1);   Now when we run this query in Ms Sql Studio we don't get any errors but the query returns 1 row with over 40,000 columns. I'm guessing the # of columns might be an issue but not sure.   When doing a Google search it appears that this problem was found in the 2005 and fixed in that version. Have any of you come across this problem?  

User.Identity.Name returns blank

  
Hello, I have a strange problem when trying to get the user name. When I run the asp.net page from local machie it works, but when I run it from the server it doesn't. It's very strange, I have tryied with the following functions: Page.User.Identity.Name System.Web.HttpContext.Current.User.Identity.Name My.User.Name System.Threading.Thread.CurrentPrincipal.Identity.Name User.Identity.Name   All options returns blank :s when I run it in the server Anyone have had the same problem, that could help me please? Thanks in advance.    Also I have the following in web.config <identity impersonate="false"/>    <authentication mode="Windows"/>    <authorization>      <allow users="*" />      <deny users="?" />    </authorization>  and in the IIS enabled  the anonymus authentication and enabled windows authentication  

SQLSERVER 2008 to SQL SERVER 2008 R2 REPORTS MIGRATION ISSUE?

  
Hi All, Yesterday we installed SQLSERVER 2008 R2 in our development mechine , and already it have Microsoft TFS 2008. When i open my report project it came up with the upgrade messagebox i clicked on Yes.And i try to run the reports locally its giving me exception like "An attempt has been made to  use the data extention 'custom datasource extention 1.2' that is eaither not registered for this report server or is not supported in this edition of reporting services'.So i did the changes like adding the dlls into the reportserver bin and added the data block which i have configured for SSRS 2008 i have applied the same setting for the SSRS 2008 R2 but still i am gettign the same exception do we need to do any changes in SSRS 2008 R2. because i am able to run the reports sucessuflly in SSRS 2008 but not SSRS 2008 R2? Any body have ideas on this. Thanks, Veeren.

Cannot Connect SQLServer 2008 with the provider SQLNCLI... Is there any SQL Server 2008 patch to sup

  
We have a program which developed under SQL Server 2005. In the program the provider of the connect string is hard coded as "SQLNCLI". It's ok running on SQL Server 2005. Now, for some reasons, this program must run under SQL Server 2008 (x64). But our program cannot access the SQL Server. We check the reason, found that, in SQL Server 2008, SQLNCLI is changed to SQLNCLI10, this caused our program cannot run. So I want to ask, is there any patch of SQL2008, so that the legacy program can normal access SQLserver with SQLNCLI WITHOUT rebuild a new version?  

SQL 2008 External access returns wrong address for Report Manager

  
Hello, I have problems with the external access for report server. My report server is running in a local server on port 80, which can be accessed through http://servername/reports I have set up external access to the report server through http://servername.domain.com:8081/reports , so I set up a redirection from public port 8081 to port 80 on the local server. When I write the address http://servername.domain.com:8081/reports in a browser, I get asked for user authentication(Windows domain user), which is accepted, but after that I get an error because the URL automatically changes to http://servername.domain.com/Reports/Pages/Folder.aspx (without the port 8081) If I write http://servername.domain.com:8081/Reports/Pages/Folder.aspx , it works. I can see the report manager home page and browse through my reports. But there are some links in the page that are built improperly, since they still point to the wrong URL (without port 8081). These are e.g. the Help link, the Report Builder link, the Details view link.  So I think there is something wrong with the response the report server sends, when I write ".../Reports" and returns ".../Reports/Pages/Folders.aspx" I haven't found any configuration file or property where this response is specified, neither where the report

multiple dataset in sqlserver 2008

  
show the code for how to do multiple dataset in sqlserver 2008

multiple dataset in sqlserver 2008

  
How to do multiple datset for a single report in sql server 2008  

Problems with SMO 2008 Redist + Microsoft.SqlServer.BatchParserClient

  
Hi,    I'm trying to run my application using SMO 2008. Everything works just fine if i have sql 2008 server installed.   My problem starts when I try to use SMO 2008 Redist. First it does not install Microsoft.SqlServer.BatchParserClient or Microsoft.SqlServer.BatchParser. After a little research, I found that this is a problem and that these files have to be copied manually to the folder where the application runs.  So I tried copying the files: No luck, i get a Could not load file (Below).  Then i tried to adding these files to the GAC manually: Same thing, Could not load file:   Code Snippet Microsoft.SqlServer.Management.Smo.FailedOperationException: ExecuteNonQuery failed for Database 'DB2008'.  ---> System.IO.FileLoadException: Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)        Then I looked at the version of the files and they seemed to be version 10.0.144.32, so I went to my app.config and added a bind redirection from 10.0.0.0 to 10.0.144.32. now it finds the assembly but says that Manifest doesnt mach the reference:   Code SnippetMicrosoft.SqlServer.Management.Sm

SQLServer Express 2008 R2 - Cannot connect Error: 18456, Severity: 14, State: 11.

  
I have just installed  running MSSQL Server 2008 R2 (Express), along with Visual Web Developer 2010 Express In SQL Server Configuration Manager I can see the SQL Server Service running (SQLEXPRESS) and the SQL Server Browser service running. On running SQL Server Management Studio when trying to log on I get the message Login failed for user Phil-PC`Phil (Microsoft SQL Server, Error: 18456) In the SQL Server Error log I see this error 2010-09-16 10:24:16.07 Logon       Error: 18456, Severity: 14, State: 11. 2010-09-16 10:24:16.07 Logon       Login failed for user 'Phil-PC\Phil'. Reason: Token-based server access validation failed with an infrastructure error. Check for previous errors. [CLIENT: <local machine>] I have been unable to find anything useful on Google on how to resolve this problem. I have tried running the command line utility sqlcmd -L and this lists the following Servers:     Phil-PC     Phil-PC\SQLEXPRESS   In my list of Installed programs in Control Panel I see both MS SQL Server 2008 & MS SQL Server 2008 R2, is that correct?

SCOPE_IDENTITY() returns null after paramerized INSERT

  

I have a very simple database, without any triggers at this point. One of my tbales has a auto increment key (IDENTITY field). As the record has a string attribute, which valeu is received from the user, I insert a new records with a parametized INSERT statement. After insertion I try to fetch the new record's ID with the sttament SELECT SCOPE_IDENTITY(), but ti return null - while SELECT @IDENTITY and SELECT IDENT_CURRENT returns the valid values.

Moreover, if - for testing purposes - I execute the same insert without parameters, (i.e. providing the string value directly in the INSERT statement), then even SCOPE_IDENTITY() returns the correct value.

I didn't find any reference in the documentation regarding such restriction. Is is a known bug or the result of some misunderstading?


SQLSERVER 2008 - FILESTREAM - filename filesystem

  

hello, i use filestream sqlserver 2008. When a file is inserted on sqlserver filestream, this file is put on a directory and rename with this: "00000055-000000f9-0009" for example. If you add extension (jpg for example), you can open this file. It's good. But, i dont't know how get the name "00000055-000000f9-0009" for example when i have my colum filestream of my table and the uniqueidentifier.

It is important for me because i wan't to access to this file if my application have a problem. I am administrator DBA sqlserver and i wan't to retrieve the correspondance and file GUID of my table and file system "xxxxxxxx-xxxxxxxx-xxxx" created.

Thanks


SQLServer 2008 R2 180 days Evaluation copy download

  

The download manager for the file

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=54ad6107-c552-4d47-b1a1-3f66460f71a9&displaylang=en

does not work. returns error:

The server returned an error. Would you like to retry.

 

Still does not work


Upgraded SQLServer 2008 Enterprise Evaluation after 180 day period expired...Services start but stil

  

Hello,

I have a SQLServer 2008 Enterprise (180 day eval) installation that had expired.

I downloaded and intalled SQLServer 2008 Enterprise (Full version) from Technet

and ran the "Version Upgrade" tool.

The Upgrade tool correctly identified the expired instance and reported that it

had successfully upgraded the expired instance.

The OS processes will start but when I attempt a connect, I get a "Evaluation Period Expired"

error message.

Is it possible to do an "upgrade in place" after the 180 day evaluation has expired or do

you have to uninstall then re-install ?

Many Thanks in Advance,

Hobson Black


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend