Showing posts with label user. Show all posts
Showing posts with label user. Show all posts

Friday, March 30, 2012

problem with SQLConnection

I am working on a set of webforms that insert user data into a set of db tables.

I set up a test of an approach using northwind and I'm having trouble getting the insert to work. When I open the form, input the name and phone, and submit there is no error, but no record inserted into the Shippers table.

You can see one of my approaches in the ASPX code. I don't like having to do the select in order to do the insert -- so that's commented off.

I'm stuck. Thoughts about what I'm missing appreciated...

Ray

ASPX code.

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default66a.aspx.cs"Inherits="pages_audit_Default66a" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headid="Head1"runat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

CompanyName:

<asp:textboxid="txtCompanyName"runat="server"/><br/>

Phone:

<asp:textboxid="txtPhone"runat="server"/><br/>

<br/>

<asp:buttonid="btnSubmit"runat="server"text="Submit"onclick="btnSubmit_Click"/>

<br/>

<br/>

<br/>

<br/>

<asp:LabelID="awesomelbl"runat="server"Text="Label"></asp:Label><br/>

<br/>

<!--

<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"

insertcommand="INSERT INTO Shippers(CompanyName, Phone) VALUES (@.CompanyName, @.Phone)" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Shippers]">

<insertparameters>

<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />

<asp:controlparameter controlid="txtPhone" name="Phone" />

</insertparameters>

</asp:sqldatasource>

-->

</form>

</body>

</html>

c Sharp code

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.Sql;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclasspages_audit_Default66a : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedvoid btnSubmit_Click(object sender,EventArgs e)

{

SqlConnection con =newSqlConnection("Data Source=Chilibowl;Trusted_Connection=yes;DataBase=Northwind");

SqlCommand cmd =newSqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@.CompanyName, @.Phone)");

SqlParameter cnameparam =newSqlParameter("@.CompanyName", txtCompanyName.Text);SqlParameter phnparam =newSqlParameter("@.Phone", txtPhone.Text);

cmd.Parameters.Add(cnameparam);

cmd.Parameters.Add(phnparam);

try

{

con.Open();

if (cmd.ExecuteNonQuery() > 0)awesomelbl.Text ="successful insert";

}

catch

{

//handel

}

finally

{

con.Close();

}

}

}

rkobs:

SqlCommand cmd =newSqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@.CompanyName, @.Phone)");

Try this:

SqlCommand cmd =newSqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@.CompanyName, @.Phone)",con);

|||

Worked. Thanks.

Ray

sql

Problem with sql2005 query/storedproc

I am working on the login portion of my app and am using my own setup for the moment so that I can learn more about how things work. I have 1 user setup in the db and am using a stored procedure to do the checking for me, here is the stored procedure code:

ALTER PROCEDUREdbo.MemberLogin(@.MemberNamenchar(20),

@.MemberPasswordnchar(15),

@.BoolLoginbit OUTPUT

)

AS

selectMemberPasswordfrommemberswheremembername = @.MemberNameandmemberpassword = @.MemberPassword

if@.@.Rowcount = 0

begin

selectBoolLogin = 0

return

end

selectBoolLogin=1

/* SET NOCOUNT ON */

RETURN

When I run my app, I continue to get login failed but no error messages. Can anybody help? Here is my vb code:

Dim MemberNameAsString

Dim MemberPasswordAsString

Dim BoolLoginAsBoolean

Dim DBConnectionAsNew Data.SqlClient.SqlConnection(MyCONNECTIONSTRING)

Dim SelectMembersAsNew Data.SqlClient.SqlCommand("MemberLogin", DBConnection)

SelectMembers.CommandType = Data.CommandType.StoredProcedure

MemberName = txtLogin.Text

MemberPassword = txtPassword.Text

Dim SelectMembersParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter

'Name

SelectMembersParameter.ParameterName ="@.MemberName"

SelectMembersParameter.Value = MemberName

SelectMembers.Parameters.Add(SelectMembersParameter)

'Password

Dim SelectPasswordParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter

SelectPasswordParameter.ParameterName ="@.MemberPassword"

SelectPasswordParameter.Value = MemberPassword

SelectMembers.Parameters.Add(SelectPasswordParameter)

Dim SelectReturnParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter

SelectReturnParameter.ParameterName ="@.BoolLogin"

SelectReturnParameter.Value = BoolLogin

SelectReturnParameter.Direction = Data.ParameterDirection.Output

SelectMembers.Parameters.Add(SelectReturnParameter)

If BoolLogin =FalseThen

MsgBox("Login Failed")

ElseIf BoolLogin =TrueThen

MsgBox("Login Successful")

EndIf

EndSub

Thank you!!!

Perhaps its because of the nchar's you are using. CHAR is used for a fixed width string so if you send in a string which is less than the specified length it will be padded with extra spaces at the end. I would modify your code as follows:

ALTER PROCEDURE dbo.MemberLogin(@.MemberNamenvarchar(20),@.MemberPasswordnvarchar(15),@.BoolLoginbit OUTPUT)ASBEGINSET NOCOUNT ON-- @.BoolLogin =0 ==> Does not exist, @.BoolLogin=1 ==> ExistsSET @.BoolLogin =0IFEXISTS(select MemberPasswordfrom memberswhere membername = @.MemberNameand memberpassword = @.MemberPassword)SET @.BoolLogin = 1SET NOCOUNT OFFEND
|||

Hello all, I am still having problems and am very frustrated. I have looked and ready over a dozen articles on ado/asp/sql and cannot seem to figure this out. I have a sql db I added using the add components part of asp. It is local, IIS is active. As far as i can tell servername is 'local'. This is the code I am running:

visual basic code:
Imports System.DataImports System.Data.SqlClientPartialClass _DefaultInherits System.Web.UI.PagePrivateConst MyCONNECTIONSTRINGAsString = "Server=(local);Database=Vex;Trusted_Connection=True"ProtectedSub btnLogin_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles btnLogin.ClickDim MemberNameAsStringDim MemberPasswordAsStringDim BoolLoginAsBooleanDim testAsStringDim DBConnectionAsNew Data.SqlClient.SqlConnection(MyCONNECTIONSTRING)Dim SelectMembersAsNew Data.SqlClient.SqlCommand("MemberLogin", DBConnection) SelectMembers.CommandType = Data.CommandType.StoredProcedure 'open the connection to the db DBConnection.Open() MemberName = txtLogin.Text MemberPassword = txtPassword.Text 'NameDim SelectMembersParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter SelectMembersParameter.ParameterName = "@.MemberName" SelectMembersParameter.Value = MemberName SelectMembers.Parameters.Add(SelectMembersParameter) 'PasswordDim SelectPasswordParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter SelectPasswordParameter.ParameterName = "@.MemberPassword" SelectPasswordParameter.Value = MemberPassword SelectMembers.Parameters.Add(SelectPasswordParameter) 'Pass or Fail VariableDim SelectReturnParameterAs Data.SqlClient.SqlParameter = SelectMembers.CreateParameter SelectReturnParameter.ParameterName = "@.BoolLogin" SelectReturnParameter.Value = BoolLogin SelectReturnParameter.Direction = Data.ParameterDirection.Output SelectMembers.Parameters.Add(SelectReturnParameter) test = SelectMembers.ExecuteScalar()EndSubEndClass

I get this error when i try to login on the .open line:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

If i try to execute the .scalar w/o the line it tells me i need an open connection, but when I try to open the connection it throws this error. What am I doing wrong? Is there some setup piece(s) I am missing? I have gone through a basic install of vs2005 with no settings changes to sql05. Any help is greatly appreciated as I am at my wits end with this and I know it is going to be something simple......

as an added note, here is the connection string in the web.config file:

visual basic code:
<connectionStrings> <add name="csVex" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Vex.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings>
I went into sql2005 surface configuration and made sure all protocols are enabled. I am an admin locally on my machine. I do not know what else to check or do at this point.

Thanks for your help....

|||

Just in case anybody else runs into this. I created a new project and added a datasource to that project pointing to my sql 2005 database. I then copied the connectionstring from that connection and pasted it in my CONST connectionstring. Error went away.

Good Luck!!

Wednesday, March 28, 2012

Problem with SQL services

When I reset or restart windows, the services mssqlserver
and the agent dont start.
I have this services configured with a administrator
domain user in the log on properties and for some reason
this services dont authenticate the password user I
received a error with the login but If I will to the
properties services and write the same password, the
service start.
The question is why dont start this services
automatically?
I change the password of this user and I have the same
problem.
My s.o. is win2000 sp4 and sql 2000 with sp3 in english
and this machine is a member of a w2000 domain.
I wait taht us understand me.
Regards,
Roque.In the properties of SQL Server (can be accessed from Enterprise manager by
right clicking on server), make sure "Auto start SQL Server Agent" is
checked.
ashish
"Roque Catanese" <anonymous@.discussions.microsoft.com> wrote in message
news:900e01c3e9cb$ab25f410$a601280a@.phx.gbl...
quote:

> When I reset or restart windows, the services mssqlserver
> and the agent dont start.
> I have this services configured with a administrator
> domain user in the log on properties and for some reason
> this services dont authenticate the password user I
> received a error with the login but If I will to the
> properties services and write the same password, the
> service start.
> The question is why dont start this services
> automatically?
> I change the password of this user and I have the same
> problem.
> My s.o. is win2000 sp4 and sql 2000 with sp3 in english
> and this machine is a member of a w2000 domain.
> I wait taht us understand me.
> Regards,
> Roque.

Problem with SQL services

When I reset or restart windows, the services mssqlserver
and the agent dont start.
I have this services configured with a administrator
domain user in the log on properties and for some reason
this services dont authenticate the password user I
received a error with the login but If I will to the
properties services and write the same password, the
service start.
The question is why dont start this services
automatically?
I change the password of this user and I have the same
problem.
My s.o. is win2000 sp4 and sql 2000 with sp3 in english
and this machine is a member of a w2000 domain.
I wait taht us understand me.
Regards,
Roque.In the properties of SQL Server (can be accessed from Enterprise manager by
right clicking on server), make sure "Auto start SQL Server Agent" is
checked.
ashish
"Roque Catanese" <anonymous@.discussions.microsoft.com> wrote in message
news:900e01c3e9cb$ab25f410$a601280a@.phx.gbl...
> When I reset or restart windows, the services mssqlserver
> and the agent dont start.
> I have this services configured with a administrator
> domain user in the log on properties and for some reason
> this services dont authenticate the password user I
> received a error with the login but If I will to the
> properties services and write the same password, the
> service start.
> The question is why dont start this services
> automatically?
> I change the password of this user and I have the same
> problem.
> My s.o. is win2000 sp4 and sql 2000 with sp3 in english
> and this machine is a member of a w2000 domain.
> I wait taht us understand me.
> Regards,
> Roque.

Problem with SQL Server Express database...

ERROR: Cannot open user default database. Login failed. Login failed for user 'ALINE\Doug's Account'.You are here: Skip Navigation LinksHome :Our Menu :Drinks

The database service is running and my connection tests worked out ok. What's next?

TIA,

Doug

This is turning out to be a nightmare...|||You need to give ALINE\Doug's Account logon permission to your database. Check out theCREATE LOGIN topic in Books Online.

Monday, March 26, 2012

Problem with SQL Notification - cannot find a non-existant user

I am having the following error trying to get a SQL Notification to work. I have followed the "Creating a Query for Notification" at http://msdn2.microsoft.com/en-us/library/ms181122.aspx, but so far without success in resolving this.

Source:
.Net SqlClient Data Provider
Data:
System.Collections.ListDictionaryInternal
Message:
Cannot find the user 'owner', because it does not exist or you do not have permission.
Cannot find the queue 'SqlQueryNotificationService--guid deleted--',
because it does not exist or you do not have permission.
Invalid object name 'SqlQueryNotificationService--guid deleted--'.
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at SqlDependencyProcessDispatcher.SqlConnectionContainer.CreateQueueAndService(Boolean restart)
at SqlDependencyProcessDispatcher.SqlConnectionContainer..ctor(SqlConnectionContainerHashHelper hashHelper, String appDomainKey, Boolean useDefaults)
at SqlDependencyProcessDispatcher.Start(String connectionString, String& server, DbConnectionPoolIdentity& identity, String& user, String& database, String& queueService, String appDomainKey, SqlDependencyPerAppDomainDispatcher dispatcher, Boolean& errorOccurred, Boolean& appDomainStart, Boolean useDefaults)By changing the service logon account from a local one to a domain account I have stopped the above error.

problem with SQL Agent

OK this is a new error on me.
I have a SQL server 2000 on Windows Server 2003.
I have setup a Maint plan that backs up the user and system databases
and the transaction Logs on my user databases.
Does optimises and integrity checks on those databases as well.
I am not attempting to repair any minor problems.
I am not performing integrity checks before backing up the database
and transaction logs.
All of the databases that I am doing a transaction log backup on have
recovery mode of full.
When the jobs run they fail instantly with error code 22029.
Sqlmaint.exe failed to run. This was working up until the end of the
day on the Thursday before Good Friday. (last week) The transaction
log backup ran fine at 4:00 PM the same job failed at 8:00 PM. No
changes were made to the server during that time.
Another issue that started at the same time. I have a web page used to
grab data from a text file export and pull it into an AS400. I use
this server to house the DTS packages and stored procedures that the
process needs. I suddenly quit working when the jobs quit running.
We are in a mixed enviroment with most clients on AD and this server
and most others still in a NT 4 domain. We have been like this for at
least 3 months and everything has worked fine. I setup the various
users and systems the way the need to be to work.
Originally the SQL Agent was running as a generic NT 4 Domain user with
local administrator rights to the local box and server role of system
administrator. The MSSQLSERVER and DTC services were running as the
built in system account.
Everything was happy then it broke.
When I reboot the server the jobs and the website work fine. Then
after a period of time that I have not figured out yet, but more than
15 minutes and less than 2 hours. Everything quits working.
I have changed all the services to run as a domain admin with SQL
system adminsitrator server role. Still same thing.
I have changed all the services to run as the built in system account.
Still same thing.
I run the sqlmaint from command line with the switches that I am using
in the maint jobs and it runs fine.
I have run dbcc checkdb on all the databases and they are fine.
The DTS packages and the stored procedures used by the website run fine
from with in Query analyzer.
Any help you can provide would be greatly appreciated.A guess: Try disabling the IPSec service. I've seen some similar behavior
when this service was misconfigured.
Also I would make sure the system is configure to log all security failures
and take a good look at the Security event log for any additional clues.|||Kevin,
Thanks for the reply. I already had the security set to log failure
and it is showing nothing but success audits.
I stopped the IPSec service and I still couldn't run the job. Do i
need to restart the server after making that change?
Kevin Joyner
Kevin English wrote:
> A guess: Try disabling the IPSec service. I've seen some similar behavio
r
> when this service was misconfigured.
> Also I would make sure the system is configure to log all security failure
s
> and take a good look at the Security event log for any additional clues.

problem with SQL Agent

OK this is a new error on me.
I have a SQL server 2000 on Windows Server 2003.
I have setup a Maint plan that backs up the user and system databases
and the transaction Logs on my user databases.
Does optimises and integrity checks on those databases as well.
I am not attempting to repair any minor problems.
I am not performing integrity checks before backing up the database
and transaction logs.
All of the databases that I am doing a transaction log backup on have
recovery mode of full.
When the jobs run they fail instantly with error code 22029.
Sqlmaint.exe failed to run. This was working up until the end of the
day on the Thursday before Good Friday. (last week) The transaction
log backup ran fine at 4:00 PM the same job failed at 8:00 PM. No
changes were made to the server during that time.
Another issue that started at the same time. I have a web page used to
grab data from a text file export and pull it into an AS400. I use
this server to house the DTS packages and stored procedures that the
process needs. I suddenly quit working when the jobs quit running.
We are in a mixed enviroment with most clients on AD and this server
and most others still in a NT 4 domain. We have been like this for at
least 3 months and everything has worked fine. I setup the various
users and systems the way the need to be to work.
Originally the SQL Agent was running as a generic NT 4 Domain user with
local administrator rights to the local box and server role of system
administrator. The MSSQLSERVER and DTC services were running as the
built in system account.
Everything was happy then it broke.
When I reboot the server the jobs and the website work fine. Then
after a period of time that I have not figured out yet, but more than
15 minutes and less than 2 hours. Everything quits working.
I have changed all the services to run as a domain admin with SQL
system adminsitrator server role. Still same thing.
I have changed all the services to run as the built in system account.
Still same thing.
I run the sqlmaint from command line with the switches that I am using
in the maint jobs and it runs fine.
I have run dbcc checkdb on all the databases and they are fine.
The DTS packages and the stored procedures used by the website run fine
from with in Query analyzer.
Any help you can provide would be greatly appreciated.A guess: Try disabling the IPSec service. I've seen some similar behavior
when this service was misconfigured.
Also I would make sure the system is configure to log all security failures
and take a good look at the Security event log for any additional clues.|||Kevin,
Thanks for the reply. I already had the security set to log failure
and it is showing nothing but success audits.
I stopped the IPSec service and I still couldn't run the job. Do i
need to restart the server after making that change?
Kevin Joyner
Kevin English wrote:
> A guess: Try disabling the IPSec service. I've seen some similar behavior
> when this service was misconfigured.
> Also I would make sure the system is configure to log all security failures
> and take a good look at the Security event log for any additional clues.

problem with sql

hi
I have problem with sql. I dont userstand what should I do.
my problem is
I have table UserLocationHistory
I want those user who have latest date.
I am fired sql like
SELECT DISTINCT userid, datetime
FROM UserLocationHistory
ORDER BY userid, datetime DESC
UserID datetime
801/5/2005
801/4/2005
801/2/2005
1241/3/2005
1241/2/2005
1241/1/2005
1301/3/2005
1861/1/2005
but I wnat this reasult like
UserID datetime
801/5/2005
1241/3/2005
1301/3/2005
1861/1/2005
so please help me out
regards,
bhavik
TRY THIS:-
SELECT userid, max(datetime) as date
FROM UserLocationHistory
Group by userid
ORDER BY userid
Thanks
Hari
SQL Server MVP
"bhavik" <bhavik@.discussions.microsoft.com> wrote in message
news:E157B034-E349-4EA8-B165-3BDC557EBE6F@.microsoft.com...
> hi
> I have problem with sql. I dont userstand what should I do.
> my problem is
> I have table UserLocationHistory
> I want those user who have latest date.
> I am fired sql like
> SELECT DISTINCT userid, datetime
> FROM UserLocationHistory
> ORDER BY userid, datetime DESC
> UserID datetime
> 80 1/5/2005
> 80 1/4/2005
> 80 1/2/2005
> 124 1/3/2005
> 124 1/2/2005
> 124 1/1/2005
> 130 1/3/2005
> 186 1/1/2005
>
> but I wnat this reasult like
> UserID datetime
> 80 1/5/2005
> 124 1/3/2005
> 130 1/3/2005
> 186 1/1/2005
> so please help me out
> regards,
> bhavik
|||thanks Hari Prasad
your are GRATE.
bhavik shah
"Hari Prasad" wrote:

> TRY THIS:-
>
> SELECT userid, max(datetime) as date
> FROM UserLocationHistory
> Group by userid
> ORDER BY userid
> Thanks
> Hari
> SQL Server MVP
>
> "bhavik" <bhavik@.discussions.microsoft.com> wrote in message
> news:E157B034-E349-4EA8-B165-3BDC557EBE6F@.microsoft.com...
>
>

Friday, March 23, 2012

Problem with sp_change_users_login

Hello,
I am trying to connect the user 'dbo' for a user database to an existing SQL
Server login, which, according to SQL Server BOL, should be accomplished by
using this syntax:
use MyUserDB
go
sp_change_users_login 'update_one', 'dbo', 'MyServerLogin'
I get an error message stating that 'dbo' is a forbidden value for the login
parameter in this procedure.
I tried reversing the order, but I get the same error.
If anyone has any clues to what is wrong I would appreciate a comment
I am working with a server which is to be a backup server for one of our Web
servers.
I am changing the setup to match the live server, where the 'dbo' user is
mapped to a login.
I did not set up either of them initially and I am not quite sure which user
names have to have a login, so I am playing it safe by matching the setup of
the live server.
Thank you
Ragnar
Use "sp_changedbowner"
Geoff N. Hiten
Microsoft SQL Server MVP
"Ragnar Midtskogen" <ragnar_ng@.newsgroups.com> wrote in message
news:O6CaM$vWFHA.2060@.tk2msftngp13.phx.gbl...
> Hello,
> I am trying to connect the user 'dbo' for a user database to an existing
> SQL Server login, which, according to SQL Server BOL, should be
> accomplished by using this syntax:
> use MyUserDB
> go
> sp_change_users_login 'update_one', 'dbo', 'MyServerLogin'
> I get an error message stating that 'dbo' is a forbidden value for the
> login parameter in this procedure.
> I tried reversing the order, but I get the same error.
> If anyone has any clues to what is wrong I would appreciate a comment
> I am working with a server which is to be a backup server for one of our
> Web servers.
> I am changing the setup to match the live server, where the 'dbo' user is
> mapped to a login.
> I did not set up either of them initially and I am not quite sure which
> user names have to have a login, so I am playing it safe by matching the
> setup of the live server.
> Thank you
> Ragnar
>
|||Thank you Geoff,
It worked!
I did not try that because according to sp_helpdb the user with the login I
want to connect to dbo was already the owner.
However, when I displayed the users for the DB there was no login name shown
for the dbo user.
In the logins, under Security, this user name has the master as the default
DB, but that is true for the live server too.
I thought maybe this was similar to a case of orphaned users, which happens
when I restore database from a backup of the live server DB, even though dbo
was not shown as an orphaned user when I ran the report..
BTW, I assume the problem with orphaned users is because I have not been
able to restore the master DB with a backup from the live server, because I
have not been able to start SQL Server in single user mode.
I stop it, then start it from the command line with sqlservr.exe -c, -m, as
described in SQL Server BOL
Ragnar

Problem with sp_change_users_login

Hello,
I am trying to connect the user 'dbo' for a user database to an existing SQL
Server login, which, according to SQL Server BOL, should be accomplished by
using this syntax:
use MyUserDB
go
sp_change_users_login 'update_one', 'dbo', 'MyServerLogin'
I get an error message stating that 'dbo' is a forbidden value for the login
parameter in this procedure.
I tried reversing the order, but I get the same error.
If anyone has any clues to what is wrong I would appreciate a comment
I am working with a server which is to be a backup server for one of our Web
servers.
I am changing the setup to match the live server, where the 'dbo' user is
mapped to a login.
I did not set up either of them initially and I am not quite sure which user
names have to have a login, so I am playing it safe by matching the setup of
the live server.
Thank you
RagnarUse "sp_changedbowner"
Geoff N. Hiten
Microsoft SQL Server MVP
"Ragnar Midtskogen" <ragnar_ng@.newsgroups.com> wrote in message
news:O6CaM$vWFHA.2060@.tk2msftngp13.phx.gbl...
> Hello,
> I am trying to connect the user 'dbo' for a user database to an existing
> SQL Server login, which, according to SQL Server BOL, should be
> accomplished by using this syntax:
> use MyUserDB
> go
> sp_change_users_login 'update_one', 'dbo', 'MyServerLogin'
> I get an error message stating that 'dbo' is a forbidden value for the
> login parameter in this procedure.
> I tried reversing the order, but I get the same error.
> If anyone has any clues to what is wrong I would appreciate a comment
> I am working with a server which is to be a backup server for one of our
> Web servers.
> I am changing the setup to match the live server, where the 'dbo' user is
> mapped to a login.
> I did not set up either of them initially and I am not quite sure which
> user names have to have a login, so I am playing it safe by matching the
> setup of the live server.
> Thank you
> Ragnar
>|||Thank you Geoff,
It worked!
I did not try that because according to sp_helpdb the user with the login I
want to connect to dbo was already the owner.
However, when I displayed the users for the DB there was no login name shown
for the dbo user.
In the logins, under Security, this user name has the master as the default
DB, but that is true for the live server too.
I thought maybe this was similar to a case of orphaned users, which happens
when I restore database from a backup of the live server DB, even though dbo
was not shown as an orphaned user when I ran the report..
BTW, I assume the problem with orphaned users is because I have not been
able to restore the master DB with a backup from the live server, because I
have not been able to start SQL Server in single user mode.
I stop it, then start it from the command line with sqlservr.exe -c, -m, as
described in SQL Server BOL
Ragnarsql

Problem with sp_change_users_login

Hello,
I am trying to connect the user 'dbo' for a user database to an existing SQL
Server login, which, according to SQL Server BOL, should be accomplished by
using this syntax:
use MyUserDB
go
sp_change_users_login 'update_one', 'dbo', 'MyServerLogin'
I get an error message stating that 'dbo' is a forbidden value for the login
parameter in this procedure.
I tried reversing the order, but I get the same error.
If anyone has any clues to what is wrong I would appreciate a comment
I am working with a server which is to be a backup server for one of our Web
servers.
I am changing the setup to match the live server, where the 'dbo' user is
mapped to a login.
I did not set up either of them initially and I am not quite sure which user
names have to have a login, so I am playing it safe by matching the setup of
the live server.
Thank you
RagnarUse "sp_changedbowner"
Geoff N. Hiten
Microsoft SQL Server MVP
"Ragnar Midtskogen" <ragnar_ng@.newsgroups.com> wrote in message
news:O6CaM$vWFHA.2060@.tk2msftngp13.phx.gbl...
> Hello,
> I am trying to connect the user 'dbo' for a user database to an existing
> SQL Server login, which, according to SQL Server BOL, should be
> accomplished by using this syntax:
> use MyUserDB
> go
> sp_change_users_login 'update_one', 'dbo', 'MyServerLogin'
> I get an error message stating that 'dbo' is a forbidden value for the
> login parameter in this procedure.
> I tried reversing the order, but I get the same error.
> If anyone has any clues to what is wrong I would appreciate a comment
> I am working with a server which is to be a backup server for one of our
> Web servers.
> I am changing the setup to match the live server, where the 'dbo' user is
> mapped to a login.
> I did not set up either of them initially and I am not quite sure which
> user names have to have a login, so I am playing it safe by matching the
> setup of the live server.
> Thank you
> Ragnar
>|||Thank you Geoff,
It worked!
I did not try that because according to sp_helpdb the user with the login I
want to connect to dbo was already the owner.
However, when I displayed the users for the DB there was no login name shown
for the dbo user.
In the logins, under Security, this user name has the master as the default
DB, but that is true for the live server too.
I thought maybe this was similar to a case of orphaned users, which happens
when I restore database from a backup of the live server DB, even though dbo
was not shown as an orphaned user when I ran the report..
BTW, I assume the problem with orphaned users is because I have not been
able to restore the master DB with a backup from the live server, because I
have not been able to start SQL Server in single user mode.
I stop it, then start it from the command line with sqlservr.exe -c, -m, as
described in SQL Server BOL
Ragnar

Wednesday, March 21, 2012

Problem with SET QUOTED_IDENTIFIER ON

Hi,
I am creating User defined function with
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
But function is created with QUOTED_IDENTIFIER OFF and SET ANSI_NULLS OFF.
What is wrong.
ThanksHi,
look here, Iposted that some time ago:
http://forums.microsoft.com/MSDN/Sh...228076&SiteID=1
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--|||How do you know the settings are OFF? What version of SQL Server? The
following works for me under SQL 2000:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION dbo.TestFunction(@.Parameter1 int)
RETURNS int
AS
BEGIN
RETURN @.Parameter1
END
GO
SELECT
OBJECTPROPERTY(OBJECT_ID('dbo.TestFunction'), 'ExecIsAnsiNullsOn'),
OBJECTPROPERTY(OBJECT_ID('dbo.TestFunction'), 'ExecIsQuotedIdentOn')
GO
Hope this helps.
Dan Guzman
SQL Server MVP
"AMiha" <amiha@.hotmail.com.false> wrote in message
news:urdlGKmTGHA.5496@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I am creating User defined function with
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> But function is created with QUOTED_IDENTIFIER OFF and SET ANSI_NULLS
> OFF.
> What is wrong.
> Thanks
>|||I'm working with sql 2000 and result of
SELECT
OBJECTPROPERTY(OBJECT_ID('dbo.myUdf'), 'ExecIsAnsiNullsOn'),
OBJECTPROPERTY(OBJECT_ID('dbo.myUdf'), 'ExecIsQuotedIdentOn')
GO
is null for myUdf.
Result of
select OBJECTPROPERTY(OBJECT_ID('dbo.myUdf'), 'IsTableFunction')
is 1.
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:e7DFkFnTGHA.5900@.tk2msftngp13.phx.gbl...
> How do you know the settings are OFF? What version of SQL Server? The
> following works for me under SQL 2000:
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE FUNCTION dbo.TestFunction(@.Parameter1 int)
> RETURNS int
> AS
> BEGIN
> RETURN @.Parameter1
> END
> GO
> SELECT
> OBJECTPROPERTY(OBJECT_ID('dbo.TestFunction'), 'ExecIsAnsiNullsOn'),
> OBJECTPROPERTY(OBJECT_ID('dbo.TestFunction'), 'ExecIsQuotedIdentOn')
> GO
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "AMiha" <amiha@.hotmail.com.false> wrote in message
> news:urdlGKmTGHA.5496@.TK2MSFTNGP11.phx.gbl...
>|||The 'sticky' SET options for table valued functions are apparently not
reported correctly in SQL 2000 SP4. The create-time settings are used for
execution though. No problem in SQL 2005.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE FUNCTION dbo.myTableFunction(@.Parameter1 int)
RETURNS TABLE
AS
RETURN (SELECT 1 AS test)
GO
CREATE FUNCTION dbo.myInLineFunction(@.Parameter1 int)
RETURNS @.MyTable TABLE (Col1 int)
AS
BEGIN
RETURN
END
GO
CREATE FUNCTION dbo.myScalarFunction(@.Parameter1 int)
RETURNS int
AS
BEGIN
RETURN 1
END
GO
SELECT
OBJECTPROPERTY(id, 'IsInLineFunction'),
OBJECTPROPERTY(id, 'IsScalarFunction'),
OBJECTPROPERTY(id, 'IsTableFunction'),
OBJECTPROPERTY(id, 'ExecIsQuotedIdentOn'),
OBJECTPROPERTY(id, 'ExecIsQuotedIdentOn')
FROM sysobjects
WHERE id IN
(
OBJECT_ID('dbo.myTableFunction'),
OBJECT_ID('dbo.myInLineFunction'),
OBJECT_ID('dbo.myScalarFunction')
)
Hope this helps.
Dan Guzman
SQL Server MVP
"AMiha" <amiha@.hotmail.com.false> wrote in message
news:umq0ocnTGHA.4452@.TK2MSFTNGP12.phx.gbl...
> I'm working with sql 2000 and result of
> SELECT
> OBJECTPROPERTY(OBJECT_ID('dbo.myUdf'), 'ExecIsAnsiNullsOn'),
> OBJECTPROPERTY(OBJECT_ID('dbo.myUdf'), 'ExecIsQuotedIdentOn')
> GO
> is null for myUdf.
> Result of
> select OBJECTPROPERTY(OBJECT_ID('dbo.myUdf'), 'IsTableFunction')
> is 1.
>
> "Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
> news:e7DFkFnTGHA.5900@.tk2msftngp13.phx.gbl...
>|||Thank you Dan
"Dan Guzman" <guzmanda@.nospam-online.sbcglobal.net> wrote in message
news:e4CxrBoTGHA.196@.TK2MSFTNGP10.phx.gbl...
> The 'sticky' SET options for table valued functions are apparently not
> reported correctly in SQL 2000 SP4. The create-time settings are used for
> execution though. No problem in SQL 2005.
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE FUNCTION dbo.myTableFunction(@.Parameter1 int)
> RETURNS TABLE
> AS
> RETURN (SELECT 1 AS test)
> GO
> CREATE FUNCTION dbo.myInLineFunction(@.Parameter1 int)
> RETURNS @.MyTable TABLE (Col1 int)
> AS
> BEGIN
> RETURN
> END
> GO
> CREATE FUNCTION dbo.myScalarFunction(@.Parameter1 int)
> RETURNS int
> AS
> BEGIN
> RETURN 1
> END
> GO
> SELECT
> OBJECTPROPERTY(id, 'IsInLineFunction'),
> OBJECTPROPERTY(id, 'IsScalarFunction'),
> OBJECTPROPERTY(id, 'IsTableFunction'),
> OBJECTPROPERTY(id, 'ExecIsQuotedIdentOn'),
> OBJECTPROPERTY(id, 'ExecIsQuotedIdentOn')
> FROM sysobjects
> WHERE id IN
> (
> OBJECT_ID('dbo.myTableFunction'),
> OBJECT_ID('dbo.myInLineFunction'),
> OBJECT_ID('dbo.myScalarFunction')
> )
>
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "AMiha" <amiha@.hotmail.com.false> wrote in message
> news:umq0ocnTGHA.4452@.TK2MSFTNGP12.phx.gbl...
>

Problem with Service Principle Name after new install

Hi all,
I installed a SQL Server 2000 on a Win2003 machine, running the SQL Server
service under a domain user account.
When the SQL Server starts, I find a warning in the event log:
Source: MSSQLServer EventID: 19011
Description: SuperSocket info: (SpnRegister) : Error 8344.
After reading several KB articles I understand that the service account
tries to register the Service Principle Name on startup and fails because it
does not have the rights the register the SPN in Active Directory.
I put the account in the local admin group on the server and created a SPN
with setspn.exe from Win2000 resource kit, which points to at the domain
account. Does not fix the warning message.
I do not want to put the account into domain admin group, which would fix
the problem I think, because domain admins have all permissions to register
the SPN.
Does someone have a hint for me?
Thanks in advance
Regards
Christian
If your server should always work using same tcp port, you may ignore this
message.
If server works under LocalSystem or other account which has such
permissions (by default - only Domain Admins), he registers SPN at startup
and unregisters at shutdown. So in your case if you change tcp/ip settings
for server, you will have to reregister SPN manually. Or you may give such
rights to service account - see this article for permissions info:
http://technet2.microsoft.com/Window...e47441033.mspx
WBR, Evergray
Words mean nothing...
"Christian Guntsche" <christian.guntsche@.docuware.com> wrote in message
news:OxLkQH1RGHA.1688@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> I installed a SQL Server 2000 on a Win2003 machine, running the SQL Server
> service under a domain user account.
> When the SQL Server starts, I find a warning in the event log:
> Source: MSSQLServer EventID: 19011
> Description: SuperSocket info: (SpnRegister) : Error 8344.
> After reading several KB articles I understand that the service account
> tries to register the Service Principle Name on startup and fails because
> it does not have the rights the register the SPN in Active Directory.
> I put the account in the local admin group on the server and created a SPN
> with setspn.exe from Win2000 resource kit, which points to at the domain
> account. Does not fix the warning message.
> I do not want to put the account into domain admin group, which would fix
> the problem I think, because domain admins have all permissions to
> register the SPN.
> Does someone have a hint for me?
> Thanks in advance
> Regards
> Christian
>
|||Thanks for reply,
at least you pointed us in the right direction.
I read the article, but again MS describes not which rights an account needs
in order to register the SPN at startup. All information you get is, that it
works with domain admin rights and with local system.
Nonetheless, the information, that a special function is executed in Active
Directory let us search through the Advanced Active Directory permission
settings and we found that giving the permission to "write public
information" to the SQL Service Account solves the problem.
This prevents us from assigning domain admin rights.
Strange, that Microsoft does not point out which specific permissions have
to be set for a normal user account, but in the other tells you to not use a
admin account.
Anyway this is solved for us.
Regards
Christian
"Oleksandr Chuchko" <forlists@.mail.ru> schrieb im Newsbeitrag
news:%23JIEvO5RGHA.5036@.TK2MSFTNGP12.phx.gbl...
> If your server should always work using same tcp port, you may ignore this
> message.
> If server works under LocalSystem or other account which has such
> permissions (by default - only Domain Admins), he registers SPN at startup
> and unregisters at shutdown. So in your case if you change tcp/ip settings
> for server, you will have to reregister SPN manually. Or you may give such
> rights to service account - see this article for permissions info:
> http://technet2.microsoft.com/Window...e47441033.mspx
> --
> WBR, Evergray
> --
> Words mean nothing...
>
> "Christian Guntsche" <christian.guntsche@.docuware.com> wrote in message
> news:OxLkQH1RGHA.1688@.TK2MSFTNGP11.phx.gbl...
>

Problem with Service Principle Name after new install

Hi all,
I installed a SQL Server 2000 on a Win2003 machine, running the SQL Server
service under a domain user account.
When the SQL Server starts, I find a warning in the event log:
Source: MSSQLServer EventID: 19011
Description: SuperSocket info: (SpnRegister) : Error 8344.
After reading several KB articles I understand that the service account
tries to register the Service Principle Name on startup and fails because it
does not have the rights the register the SPN in Active Directory.
I put the account in the local admin group on the server and created a SPN
with setspn.exe from Win2000 resource kit, which points to at the domain
account. Does not fix the warning message.
I do not want to put the account into domain admin group, which would fix
the problem I think, because domain admins have all permissions to register
the SPN.
Does someone have a hint for me?
Thanks in advance
Regards
ChristianIf your server should always work using same tcp port, you may ignore this
message.
If server works under LocalSystem or other account which has such
permissions (by default - only Domain Admins), he registers SPN at startup
and unregisters at shutdown. So in your case if you change tcp/ip settings
for server, you will have to reregister SPN manually. Or you may give such
rights to service account - see this article for permissions info:
http://technet2.microsoft.com/Windo...de47441033.mspx
WBR, Evergray
--
Words mean nothing...
"Christian Guntsche" <christian.guntsche@.docuware.com> wrote in message
news:OxLkQH1RGHA.1688@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> I installed a SQL Server 2000 on a Win2003 machine, running the SQL Server
> service under a domain user account.
> When the SQL Server starts, I find a warning in the event log:
> Source: MSSQLServer EventID: 19011
> Description: SuperSocket info: (SpnRegister) : Error 8344.
> After reading several KB articles I understand that the service account
> tries to register the Service Principle Name on startup and fails because
> it does not have the rights the register the SPN in Active Directory.
> I put the account in the local admin group on the server and created a SPN
> with setspn.exe from Win2000 resource kit, which points to at the domain
> account. Does not fix the warning message.
> I do not want to put the account into domain admin group, which would fix
> the problem I think, because domain admins have all permissions to
> register the SPN.
> Does someone have a hint for me?
> Thanks in advance
> Regards
> Christian
>|||Thanks for reply,
at least you pointed us in the right direction.
I read the article, but again MS describes not which rights an account needs
in order to register the SPN at startup. All information you get is, that it
works with domain admin rights and with local system.
Nonetheless, the information, that a special function is executed in Active
Directory let us search through the Advanced Active Directory permission
settings and we found that giving the permission to "write public
information" to the SQL Service Account solves the problem.
This prevents us from assigning domain admin rights.
Strange, that Microsoft does not point out which specific permissions have
to be set for a normal user account, but in the other tells you to not use a
admin account.
Anyway this is solved for us.
Regards
Christian
"Oleksandr Chuchko" <forlists@.mail.ru> schrieb im Newsbeitrag
news:%23JIEvO5RGHA.5036@.TK2MSFTNGP12.phx.gbl...
> If your server should always work using same tcp port, you may ignore this
> message.
> If server works under LocalSystem or other account which has such
> permissions (by default - only Domain Admins), he registers SPN at startup
> and unregisters at shutdown. So in your case if you change tcp/ip settings
> for server, you will have to reregister SPN manually. Or you may give such
> rights to service account - see this article for permissions info:
> http://technet2.microsoft.com/Windo...de47441033.mspx
> --
> WBR, Evergray
> --
> Words mean nothing...
>
> "Christian Guntsche" <christian.guntsche@.docuware.com> wrote in message
> news:OxLkQH1RGHA.1688@.TK2MSFTNGP11.phx.gbl...
>sql

Problem with Service Principle Name after new install

Hi all,
I installed a SQL Server 2000 on a Win2003 machine, running the SQL Server
service under a domain user account.
When the SQL Server starts, I find a warning in the event log:
Source: MSSQLServer EventID: 19011
Description: SuperSocket info: (SpnRegister) : Error 8344.
After reading several KB articles I understand that the service account
tries to register the Service Principle Name on startup and fails because it
does not have the rights the register the SPN in Active Directory.
I put the account in the local admin group on the server and created a SPN
with setspn.exe from Win2000 resource kit, which points to at the domain
account. Does not fix the warning message.
I do not want to put the account into domain admin group, which would fix
the problem I think, because domain admins have all permissions to register
the SPN.
Does someone have a hint for me?
Thanks in advance
Regards
ChristianIf your server should always work using same tcp port, you may ignore this
message.
If server works under LocalSystem or other account which has such
permissions (by default - only Domain Admins), he registers SPN at startup
and unregisters at shutdown. So in your case if you change tcp/ip settings
for server, you will have to reregister SPN manually. Or you may give such
rights to service account - see this article for permissions info:
http://technet2.microsoft.com/WindowsServer/en/Library/8127f5ed-4e05-4822-bfa9-402ceede47441033.mspx
--
WBR, Evergray
--
Words mean nothing...
"Christian Guntsche" <christian.guntsche@.docuware.com> wrote in message
news:OxLkQH1RGHA.1688@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> I installed a SQL Server 2000 on a Win2003 machine, running the SQL Server
> service under a domain user account.
> When the SQL Server starts, I find a warning in the event log:
> Source: MSSQLServer EventID: 19011
> Description: SuperSocket info: (SpnRegister) : Error 8344.
> After reading several KB articles I understand that the service account
> tries to register the Service Principle Name on startup and fails because
> it does not have the rights the register the SPN in Active Directory.
> I put the account in the local admin group on the server and created a SPN
> with setspn.exe from Win2000 resource kit, which points to at the domain
> account. Does not fix the warning message.
> I do not want to put the account into domain admin group, which would fix
> the problem I think, because domain admins have all permissions to
> register the SPN.
> Does someone have a hint for me?
> Thanks in advance
> Regards
> Christian
>|||Thanks for reply,
at least you pointed us in the right direction. :)
I read the article, but again MS describes not which rights an account needs
in order to register the SPN at startup. All information you get is, that it
works with domain admin rights and with local system.
Nonetheless, the information, that a special function is executed in Active
Directory let us search through the Advanced Active Directory permission
settings and we found that giving the permission to "write public
information" to the SQL Service Account solves the problem.
This prevents us from assigning domain admin rights.
Strange, that Microsoft does not point out which specific permissions have
to be set for a normal user account, but in the other tells you to not use a
admin account.
Anyway this is solved for us.
Regards
Christian
"Oleksandr Chuchko" <forlists@.mail.ru> schrieb im Newsbeitrag
news:%23JIEvO5RGHA.5036@.TK2MSFTNGP12.phx.gbl...
> If your server should always work using same tcp port, you may ignore this
> message.
> If server works under LocalSystem or other account which has such
> permissions (by default - only Domain Admins), he registers SPN at startup
> and unregisters at shutdown. So in your case if you change tcp/ip settings
> for server, you will have to reregister SPN manually. Or you may give such
> rights to service account - see this article for permissions info:
> http://technet2.microsoft.com/WindowsServer/en/Library/8127f5ed-4e05-4822-bfa9-402ceede47441033.mspx
> --
> WBR, Evergray
> --
> Words mean nothing...
>
> "Christian Guntsche" <christian.guntsche@.docuware.com> wrote in message
> news:OxLkQH1RGHA.1688@.TK2MSFTNGP11.phx.gbl...
>> Hi all,
>> I installed a SQL Server 2000 on a Win2003 machine, running the SQL
>> Server service under a domain user account.
>> When the SQL Server starts, I find a warning in the event log:
>> Source: MSSQLServer EventID: 19011
>> Description: SuperSocket info: (SpnRegister) : Error 8344.
>> After reading several KB articles I understand that the service account
>> tries to register the Service Principle Name on startup and fails because
>> it does not have the rights the register the SPN in Active Directory.
>> I put the account in the local admin group on the server and created a
>> SPN with setspn.exe from Win2000 resource kit, which points to at the
>> domain account. Does not fix the warning message.
>> I do not want to put the account into domain admin group, which would fix
>> the problem I think, because domain admins have all permissions to
>> register the SPN.
>> Does someone have a hint for me?
>> Thanks in advance
>> Regards
>> Christian
>

Tuesday, March 20, 2012

Problem with select from 2000 to 2005

I have a query which was generated by a user using a report writter, so I have no control over what the user selected or how the query was generated.

The following query runs perfectly under SQL 2000 SP 4 32 bit and has for a long time. We are testing on a SQL 2005 SP1 (2153 Build) 64 bit with the exact same data.

The following query on SQL 2000 runs in 3 seconds, on SQL 2005 ran for 42 MINUTES before we cancelled it.

SELECT
CustomerID = TABLEB.CustomerID,
CustomerName = TABLEA.Group_Name_1_A,
CustomerContact = TABLEA.Group_Name_2_A
FROM
TABLEA
RIGHT OUTER JOIN TABLEB ON (TABLEB.CustomerID=TABLEA.CustomerID)
RIGHT OUTER JOIN TABLEC ON (TABLEC.CustomerID=TABLEB.CustomerID)
WHERE
TABLEB.CustomerID
IN (.. List of 38 CustomerIDs...)

Note: TABLEA and TABLEB are actually views into TABLEC. I don't know if that is relavant or not yet.

This appears to be this problem: http://support.microsoft.com/kb/318530 which existed in 2000 and was fixed with SP3. Can anyone confirm if this problem exists in 2005?

In diagnosing the problem, several things cause the query to work properly under 2005 and return in 3 seconds: Changing the WHERE TABLEB to WHERE TABLEA. Removing the RIGHT OUTER TABLEB, which is technically unneeded. The most interesting is shortening the WHERE IN clause to only 11 items, which is not possible for the report. Removing the PK from TABLEC OR making the PK index non-clustered.

The est execution plans between 2000 and 2005 is like comparing "Apples to Automobiles". That both start with "A" and that is about the only similarity.

Any ideas?The KB article fix is there in SQL Server 2005. This is an unrelated problem. Can you please file a bug at http://connect.microsoft.com/sqlserver? Please provide a repro script that demonstrates the problem. You could use plan guides in SQL Server 2005 to force the plan to use only hash joins for example. I can't say for sure if that will help without looking at the plans between the two versions. But using plan guides is one way to avoid changing the application assuming that this problem can be solved by just changing the join type. Any other rewrite will be harder to achieve without changing the query text itself.|||I will try to recreate it using the AdventureWorks database and submit it as a bug.

Thank you|||When I try to submit feedback, it just loops when press "Submit" and apparently does nothing.

I was able to reproduce the problem on AdventureWorks using ths following script.

-- Create Test Data Table CustomerListTom and Views

USE AdventureWorks
GO

IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'ViewATom'))
DROP VIEW [ViewATom]

IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'ViewBTom'))
DROP VIEW [ViewBTom]

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'CustomerListTom') AND type in (N'U'))
DROP TABLE CustomerListTom
GO

CREATE TABLE [dbo].[CustomerListTom](
[CustomerID] [varchar](6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[RegionID] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[FirstName] [dbo].[Name] NOT NULL,
[LastName] [dbo].[Name] NOT NULL,
[EmailAddress] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AddressLine] [nvarchar](60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AddressCity] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AddressState] [nchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AddressZip] [nvarchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AddressCountry] [dbo].[Name] NOT NULL,
[Phone] [dbo].[Phone] NULL,
[BillAddressLine] [nvarchar](60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BillAddressCity] [nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BillAddressState] [nchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BillAddressZip] [nvarchar](15) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[BillAddressCountry] [dbo].[Name] NOT NULL,
[BillPhone] [dbo].[Phone] NULL,
[ModifiedDate] [datetime] NOT NULL,
)

INSERT INTO CustomerListTom
SELECT
CustomerID = RIGHT(cu.AccountNumber,6),
RegionID = RIGHT('000'+CAST(cu.TerritoryID AS VARCHAR(3)),3),
FirstName = ct.FirstName,
LastName = ct.LastName,
EmailAddress = ct.EmailAddress,
AddressLine = ad.AddressLine1,
AddressCity = ad.City,
AddressState = sp.StateProvinceCode,
AddressZip = ad.PostalCode,
AddressCountry = sp.[Name],
Phone = ct.Phone,

BillAddressLine = ad.AddressLine1,
BillAddressCity = ad.City,
BillAddressState = sp.StateProvinceCode,
BillAddressZip = ad.PostalCode,
BillAddressCountry = sp.[Name],
BillPhone = ct.Phone,

ModifiedDate = cu.ModifiedDate
--,*
FROM Sales.Customer cu
JOIN Sales.Individual id ON id.CustomerID = cu.CustomerID
JOIN Person.Contact ct ON ct.ContactID = id.ContactID
JOIN Sales.CustomerAddress ca ON cu.CustomerID = ca.CustomerID
JOIN Person.Address ad ON ad.AddressID = ca.AddressID
JOIN Person.StateProvince sp ON sp.StateProvinceID = ad.StateProvinceID

-- Create a big enough set of data for testing
DECLARE @.i INT
SET @.i = 1
WHILE (@.i < 30)
BEGIN
INSERT INTO CustomerListTom
SELECT TOP 15 PERCENT
CustomerID = RIGHT(cu.AccountNumber,6),
RegionID = RIGHT('000'+CAST(cu.TerritoryID+@.i AS VARCHAR(3)),3),
FirstName = ct.FirstName,
LastName = ct.LastName,
EmailAddress = ct.EmailAddress,
AddressLine = ad.AddressLine1,
AddressCity = ad.City,
AddressState = sp.StateProvinceCode,
AddressZip = ad.PostalCode,
AddressCountry = sp.[Name],
Phone = ct.Phone,

BillAddressLine = ad.AddressLine1,
BillAddressCity = ad.City,
BillAddressState = sp.StateProvinceCode,
BillAddressZip = ad.PostalCode,
BillAddressCountry = sp.[Name],
BillPhone = ct.Phone,

ModifiedDate = cu.ModifiedDate + CASE WHEN @.i > 3 THEN 10 ELSE -25 END + @.i

FROM Sales.Customer cu
JOIN Sales.Individual id ON id.CustomerID = cu.CustomerID
JOIN Person.Contact ct ON ct.ContactID = id.ContactID
JOIN Sales.CustomerAddress ca ON cu.CustomerID = ca.CustomerID
JOIN Person.Address ad ON ad.AddressID = ca.AddressID
JOIN Person.StateProvince sp ON sp.StateProvinceID = ad.StateProvinceID

SET @.i = @.i + 1
END

-- Cleanup - Delete Dups for PK
DELETE FROM CustomerListTom
WHERE CustomerID+RegionID IN (
SELECT CustomerID+RegionID
FROM CustomerListTom cu
GROUP BY CustomerID, RegionID
HAVING COUNT(*) > 1)

ALTER TABLE [CustomerListTom]
ADD CONSTRAINT [PK_CustomerListTom] PRIMARY KEY CLUSTERED
(
[CustomerID] ASC,
[RegionID] ASC
)

GO

-- Create Views
GO
CREATE VIEW ViewATom
AS
SELECT *
FROM CustomerListTom cu
WHERE cu.RegionID = '004'
UNION
SELECT *
FROM CustomerListTom cu
WHERE CustomerID NOT IN
(SELECT CustomerID FROM CustomerListTom c2 WHERE c2.RegionID = '004')
AND (CustomerID + CONVERT(char(8), ModifiedDate, 112) + RegionID IN
(SELECT MAX(CustomerID + CONVERT(char(8), ModifiedDate, 112) + RegionID)
FROM CustomerListTom
GROUP BY CustomerID))

GO
CREATE VIEW ViewBTom
AS
SELECT DISTINCT CustomerID
FROM CustomerListTom
GO
return

USE AdventureWorks

-- FAILURE
-- This query FAILS to return in over 15 mins, cancelled
SELECT TABLEB.CustomerID,
TABLEC.RegionID,
TABLEC.LastName,
TABLEC.FirstName
FROM ViewATom TABLEA
RIGHT OUTER JOIN ViewBTom TABLEB ON TABLEA.CustomerID = TABLEB.CustomerID
RIGHT OUTER JOIN CustomerListTom TABLEC ON TABLEC.CustomerID = TABLEB.CustomerID
WHERE TABLEB.CustomerID IN
('012870','012997','011000','011001','011002','011003','011004','011005','011006','011007',
'011008','011009','011010','011011','011012','011013','011014','011015','011016','011017',
'011018','011019','011020','011150','011153','011144','017230','017220','017254','017257',
'025338','025333','025338','025397','025389','025424','025483','025485','025682','025673',
'029478','029405','029402','029317','029109','018393'
)

return

-- SOLUTIONS
-- Change WHERE TABLEB to WHERE TABLEA, this query returns in less than 1 second
SELECT TABLEB.CustomerID,
TABLEC.RegionID,
TABLEC.LastName,
TABLEC.FirstName
FROM ViewATom TABLEA
RIGHT OUTER JOIN ViewBTom TABLEB ON TABLEA.CustomerID = TABLEB.CustomerID
RIGHT OUTER JOIN CustomerListTom TABLEC ON TABLEC.CustomerID = TABLEB.CustomerID
WHERE TABLEA.CustomerID IN
('012870','012997','011000','011001','011002','011003','011004','011005','011006','011007',
'011008','011009','011010','011011','011012','011013','011014','011015','011016','011017',
'011018','011019','011020','011150','011153','011144','017230','017220','017254','017257',
'025338','025333','025338','025397','025389','025424','025483','025485','025682','025673',
'029478','029405','029402','029317','029109','018393'
)

return

-- Remove RIGHT OUTER on TABLEB, this Query returns in less than 2 seconds
SELECT TABLEB.CustomerID,
TABLEC.RegionID,
TABLEC.LastName,
TABLEC.FirstName
FROM ViewATom TABLEA
JOIN ViewBTom TABLEB ON TABLEA.CustomerID = TABLEB.CustomerID
RIGHT OUTER JOIN CustomerListTom TABLEC ON TABLEC.CustomerID = TABLEB.CustomerID
WHERE TABLEB.CustomerID IN
('012870','012997','011000','011001','011002','011003','011004','011005','011006','011007',
'011008','011009','011010','011011','011012','011013','011014','011015','011016','011017',
'011018','011019','011020','011150','011153','011144','017230','017220','017254','017257',
'025338','025333','025338','025397','025389','025424','025483','025485','025682','025673',
'029478','029405','029402','029317','029109','018393'
)

return

-- Drop PK and run ORIGINAL query, returns in less than 4 seconds

IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[CustomerListTom]') AND name = N'PK_CustomerListTom')
ALTER TABLE [dbo].[CustomerListTom] DROP CONSTRAINT [PK_CustomerListTom]
GO

SELECT TABLEB.CustomerID,
TABLEC.RegionID,
TABLEC.LastName,
TABLEC.FirstName
FROM ViewATom TABLEA
RIGHT OUTER JOIN ViewBTom TABLEB ON TABLEA.CustomerID = TABLEB.CustomerID
RIGHT OUTER JOIN CustomerListTom TABLEC ON TABLEC.CustomerID = TABLEB.CustomerID
WHERE TABLEB.CustomerID IN
('012870','012997','011000','011001','011002','011003','011004','011005','011006','011007',
'011008','011009','011010','011011','011012','011013','011014','011015','011016','011017',
'011018','011019','011020','011150','011153','011144','017230','017220','017254','017257',
'025338','025333','025338','025397','025389','025424','025483','025485','025682','025673',
'029478','029405','029402','029317','029109','018393'
)

return

-- Create PK with NONCLUSTERED and run ORIGINAL query, returns in less than 1 second

IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[CustomerListTom]') AND name = N'PK_CustomerListTom')
ALTER TABLE [dbo].[CustomerListTom] DROP CONSTRAINT [PK_CustomerListTom]
GO
ALTER TABLE [CustomerListTom]
ADD CONSTRAINT [PK_CustomerListTom] PRIMARY KEY NONCLUSTERED
(
[CustomerID] ASC,
[RegionID] ASC
)
GO

SELECT TABLEB.CustomerID,
TABLEC.RegionID,
TABLEC.LastName,
TABLEC.FirstName
FROM ViewATom TABLEA
RIGHT OUTER JOIN ViewBTom TABLEB ON TABLEA.CustomerID = TABLEB.CustomerID
RIGHT OUTER JOIN CustomerListTom TABLEC ON TABLEC.CustomerID = TABLEB.CustomerID
WHERE TABLEB.CustomerID IN
('012870','012997','011000','011001','011002','011003','011004','011005','011006','011007',
'011008','011009','011010','011011','011012','011013','011014','011015','011016','011017',
'011018','011019','011020','011150','011153','011144','017230','017220','017254','017257',
'025338','025333','025338','025397','025389','025424','025483','025485','025682','025673',
'029478','029405','029402','029317','029109','018393'
)

return

Monday, March 12, 2012

Problem with Scheduled Jobs

I have a scheduled T-SQL job that I need to run as a different user than
system. I am running into two problems. 1, no matter who the owner is, the
job still runs as system (the SQL Server Agent User). The 2nd part is that
the "run as" is grayed out, so I can't attempt to set the step to run as a
different user.
How can I solve the problem, without changing the user that hte SQL Server
Agent runs as?
Thanks.
A job will run under the security context of the SQL Agent
service if the job is owned by a sysadmin. If it's not owned
by a sysadmin, it will run under the security context of the
proxy account. So those are your options.
-Sue
On Tue, 13 Sep 2005 09:12:08 -0400, "Kevin Antel"
<kevina@.cqlcorp.com> wrote:

>I have a scheduled T-SQL job that I need to run as a different user than
>system. I am running into two problems. 1, no matter who the owner is, the
>job still runs as system (the SQL Server Agent User). The 2nd part is that
>the "run as" is grayed out, so I can't attempt to set the step to run as a
>different user.
>How can I solve the problem, without changing the user that hte SQL Server
>Agent runs as?
>Thanks.
>

Problem with Scheduled Jobs

I have a scheduled T-SQL job that I need to run as a different user than
system. I am running into two problems. 1, no matter who the owner is, the
job still runs as system (the SQL Server Agent User). The 2nd part is that
the "run as" is grayed out, so I can't attempt to set the step to run as a
different user.
How can I solve the problem, without changing the user that hte SQL Server
Agent runs as?
Thanks.A job will run under the security context of the SQL Agent
service if the job is owned by a sysadmin. If it's not owned
by a sysadmin, it will run under the security context of the
proxy account. So those are your options.
-Sue
On Tue, 13 Sep 2005 09:12:08 -0400, "Kevin Antel"
<kevina@.cqlcorp.com> wrote:
>I have a scheduled T-SQL job that I need to run as a different user than
>system. I am running into two problems. 1, no matter who the owner is, the
>job still runs as system (the SQL Server Agent User). The 2nd part is that
>the "run as" is grayed out, so I can't attempt to set the step to run as a
>different user.
>How can I solve the problem, without changing the user that hte SQL Server
>Agent runs as?
>Thanks.
>

Problem with Scheduled Jobs

I have a scheduled T-SQL job that I need to run as a different user than
system. I am running into two problems. 1, no matter who the owner is, the
job still runs as system (the SQL Server Agent User). The 2nd part is that
the "run as" is grayed out, so I can't attempt to set the step to run as a
different user.
How can I solve the problem, without changing the user that hte SQL Server
Agent runs as?
Thanks.A job will run under the security context of the SQL Agent
service if the job is owned by a sysadmin. If it's not owned
by a sysadmin, it will run under the security context of the
proxy account. So those are your options.
-Sue
On Tue, 13 Sep 2005 09:12:08 -0400, "Kevin Antel"
<kevina@.cqlcorp.com> wrote:

>I have a scheduled T-SQL job that I need to run as a different user than
>system. I am running into two problems. 1, no matter who the owner is, th
e
>job still runs as system (the SQL Server Agent User). The 2nd part is that
>the "run as" is grayed out, so I can't attempt to set the step to run as a
>different user.
>How can I solve the problem, without changing the user that hte SQL Server
>Agent runs as?
>Thanks.
>