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

Top 5 Contributors of the Month
Post New Web Links

Retreiving @@IDENTITY from SQL Server CE returns DBNULL

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :


  I want to get the value for Identity column from the inserted session.

Right now Im using SELECT @@IDENTITY

Can somebody help me out to get the Identity value of the inserted record?

Here is what I am doing..

 int id = -1;



                bool getIdentity = true;

                var db = DatabaseFactory.CreateDatabase(EnvironmentManager.CurrentEnvironmentKey);

                using (var dbCommand = db.GetSqlStringCommand(query))


                    dbCommand.CommandType = CommandType.Text;

                    foreach (var param in dbParams)


                        if (param.ParameterName.ToLower() == "@id")


View Complete Post

More Related Resource Links

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  

SharePoint Search Server 2010 Express returns no search results for non-admin users

This is going to sound crazy, but anyway... bare with me... I have a SharePoint Search Server 2010 Express (RTM) installed with a crawl account (call it sharepoint_crawl) which has full read permission to an entire site collection of 100,000 documents. I have logged in with this account to make sure it has read access to everything, and it does. I run a full crawl of all documents and allow it to finish. If I try and search the content for an extremely common term (i.e. 50,000+ hits) I get no results. However, if I log in with a site collection admin I do get search results. There are no indexing errors or query errors in either log files or event log. Everything looks like it is working correctly - just no results for non-admins Anyone tripped on this? I have recreated the crawl account and perform a full re-index with the same results. What gets me is that the crawl account does have read permission to the content it is indexing, the content is indexed correctly, but the crawl account cannot get results back. It is as if security-trimming is removing everything. Any ideas?

Linked Server To MS Access using Jet Returns "unspecified error"

I'm have SQL SERVER 2008 on Win2008 Server. I have several linked servers to Oracle (odbc) and have just created Linked Servers to MS access 2003 databases on network shares. I can 'test connection' and select data from the linked ms access servers using 4 part naming no problem. As soon as I do this, the Oracle db links stop working. I reboot the server, test connection to Oracle dbs , all ok there, run test connection to ms access dbs and receive the following;Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "MYAccessLink"".OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "MYAccessLink" returned message "Unspecified error". (Microsoft SQL Server, Error: 7303) Reboot the server, test connection to ms access db's, all ok, then test connection to oracle, and receive the following;A transport-level error has occurred when receiving results from the server. (provider: Shared Memory Provider, error: 0 - The pipe has been ended.) (Microsoft SQL Server, Error: 109) Reboot server, perform test again, toggling the order and I get the same results.Have tried opening ms access via openrowset and "execute ('select count(*) from SomeTable') at MYAccessLink" to rule out test connection (sp_testlinkedserver) doing something to crash the links. I have checke

Identity Range Value (Max Limit Finished) SQL Server 2005 (Merge Replication Problme)


Hi ,

I am using SQL Server 2005 enterprise edition, I Confirured the Merge Replication to my database). I have a replication of 21 database from various locations.

Problem is: When is trying to remove one subriction from the publisher and add a fresh subriciton to it. it is poping any error saying the Identity Range value exceed its Max Limit try to change from int to bigint. is there any solution for it not changing from int to bigint.

Thank you.


how to create deleted row again .when i used with (identity specification) in sql server?



i have a table with 2 columns !

1- id int  identity(1,1) not null .

2 - name nvarchar(50)

and data is :

id = 1 , name = "brad pitt"

id = 3, name = "diego maradona"

how i can insert a row with id = 2 ?

SQL Server user-defined aggregate returns an error if aggregating 0 rows

I have this SQL Server user-defined aggregate:

[SqlUserDefinedAggregate(Format.UserDefined, Name="median", IsInvariantToDuplicates=false, IsInvariantToNulls=true, IsInvariantToOrder=true, IsNullIfEmpty=true, MaxByteSize=8000)] 
public class MedianCalculator : IBinarySerialize { 
    private List<double> values; 
    public void Init() { 
        values = new List<double>(); 
    public void Accumulate(SqlDouble value) { 
        if (!value.IsNull) 
    public void Merge(MedianCalculator other) { 
    public SqlDouble Terminate() { 
        if (values == null || values.Count == 0) 
            return SqlDouble.Null; 
        return (values[(int)Math.Floor((values.Count - 1) / 2.0)] + values[(int)Math.Ceiling((values.Count - 1) / 2.0)]) / 2.0; 
    public void Read(BinaryReader r) { 
        int c = r.ReadInt32(); 
        values = new List<double>(c); 
        for (int i = 0; i < c; i++) 
    public void Write(BinaryWriter w) { 
        for (int i = 0; i < values.Count; i++) 
After deploying this aggregate, I try to run this query:

WCF Data Service to Sharepoint returns items on my machine but not on server


In my ASP.NET 4.0 webapplication I have added a reference to our Sharepoint server. 

I then present some items using

      Dim Context As New Data.SharePoint.DataITDataContext(New Uri("http://sp01/data/_vti_bin/listdata.svc"))
        Context.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
        ASPxGridView1.DataSource = Context.Dokumentation.Where(Function(Item) Item.KundNr = customer.CustomerID).ToList

While running it locally on my development machine (Using Visual Studio 2010) everything works. But as soon as I publish it to the IIS, which happens to be the SharePoint server, I no longer see any records. No exception is thrown or anything, I just do'nt get any data.

Any ideas on why?

      Dim Context As New Data.SharePoint.DataITDataContext(New Uri("http://sp01/data/_vti_bin/listdata.svc"))
        Context.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials

Accessing response of HttpWebRequest, even when request returns 500 Internal Server Error



Hoping someone can point me to a solution, haven't been able to find one yet.

I'm using the standard way for send HttpWebRequest

		webRequest = (HttpWebRequest)WebRequest.Create(request.URL);
webRequest.Method = "POST";
webRequest.ContentType = "text/xml";


postStream = webRequest.GetRequestStream();
postStream.Write(requestBuffer, 0, requestBuffer.Length);
webResponse = (HttpWebResponse)webRequest.GetResponse();
responseStream = webResponse.GetResponseStream();
responseReader = new StreamReader(responseStream);
string response = responseReader.ReadToEnd();

This is all fine, working correctly, no poblems.

However the actual webservice that i'm calling returns a 500 Internal Server Error code for standard faults

HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset=utf-8
Content-Length: 703
Date: Fri, 22 Oct 2010 04:50:48 GMT

<?xml version="1.0" en
coding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.o

SSRS - Retreiving generated Parameters from Report Server created by using StoredParametersID


SSRS - Microsoft SQL Server Reporting Services Version 9.00.4309.00

Problem - StoredParametersID is an rs: (report server) parameter and is not a valid Report Parm and can not be used in web services calls as a parameter. It can not be used as <deviceinfo> and it cannot be used as a "ReportPath" in the web services call.

How can I retreive the current set of generated parameters that are created on the report server side, so I can use these to make a web services call to retreive the Drill Down report since the only method to retreive the report information seems to be a Report URL call with the StoredParametersID included.


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


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

	@RC	int,
	@ROWS	int

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

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

	@RC	int,
	@ROWS	int

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

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


if @pProjId = null
	SELECT @pProjId as newProjectID
return 0


Here is the script which creates the hip_Project Table:



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

User.Identity.Name returns app pool user instead of domain user


2 server web farm windows 2008 r2 nlb.  In IIS I enable windows authentication all other authentication is disabled.


code behind

       protected void Page_Load(object sender, EventArgs e)
            if (!Page.IsPostBack)
                Response.Write("Auth user: " + Request.ServerVariables["Auth_User"]);
                Response.Write("Logon user: " + Request.ServerVariables["LOGON_USER"]);


        <authentication mode="Windows" />        
            <deny users="?" />            

        <compilation debug="true" targetFramework="4.0" />

The code returns the application pool custom account e.g. DOMAIN\WebApp_user.  What I want is the logged in user's username.  How do I get this? 

Error installing SharePoint Server 2010 Prerequisites - Namely Windows Identity Foundation


Good day to all

i am trying to install Sharepoint server 2010 on my server, i have a windows server 2008 sbs sp2 pc. i have manually downloaded the Prerequisites and installed all except the windows identity foundation which just hangs. i have downloaded the file from the windows site namely: Windows6.0-KB974405-x64.msu, please can someone assist me in this matter i am at a lost.

ConfigurationManager.OpenExeConfiguration returns wrong config file on Home Server


I'm having an issue with
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel) where it
opens the wrong .config file when running our app on Windows Home Server.
For example, say my application is installed to:

C:\Program Files\My Application Name\myapp.exe

...and there's a corresponding config file in that directory called:

C:\Program Files\My Application Name\myapp.exe.config

...under w2k, XP, and Vista,
returns myapp.exe.config. However, under Windows Home Server, using the
exact same codebase, I get the following path:

C:\Program Files\My Application Name\myapp.config

...which is a file that doesn't exist, and doesn't contain any of our
published application configuration details.

I've seen other issues people have had issues with
ConfigurationManager.OpenExeConfiguration, but it's typically with it adding
an extra ".config", so the returned file ends up being
"myapp.exe.config.config". Our issue is slightly different; our returned
file ends up being "myapp.config"; I've looked through the code for
ConfigurationManager.OpenExeConfiguration in reflector, but I'm still not
sure why it's return

SQL 2008 to iSeries via linked server (IBMDASQL) - TOP 10 * SQL query returns ALL records


I am querying a iSeries - AS400 database from SQL server 2008 server 64 bit,  via a linked server (using OLE DB Provider - IBMDASQL)

The SQL is select top 10 * FROM <linked Svr>.<Dest server>.<DBName>.<TableName>

Instead of returning top 10 rows, the query returns ALL the rows. I use the top 10 sql query in my "Heart beat monitor" to check the viability of the linked server after a server reboot.  If the test query work



call JavaScript - jQuery code from ASP.NET Server-Side

jQuery got so close to me lately that I can see myself adding the scripts to my project almost unconsciously. The thing is, jQuery is very useful for me, in almost all situations and it has been a do or die enhancement for all my project since I first put my hands on it.

Of course while using it, you encounter few situations which need a bit of research to solve, mostly when you are trying to combine it with some other technologies like: UpdatePanels and ASP.NET Ajax. For instance there are many situations when I would like to run some jQuery magic based on some decision that I make on the server side.
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