Showing posts with label aspnet. Show all posts
Showing posts with label aspnet. Show all posts

Friday, March 9, 2012

PLEASE! - Login failed for user MACHINENAME\ASPNET.

Help!! I am using Sql Server 2005 Express.

I am trying to connect to it from an aspx page.

I get the error:

Cannot open user default database. Login failed.
Login failed for user 'MACHINENAME\ASPNET'.

I have added MACHINENAME\ASPNET as a user to the database I am trying to connect to using SQL Server Management Studio Express.

Why wont it let me connect?

Any help on the matter would be most welcome.

Thanks you.

Hi,
I use sql server 2000 but I had th same problem a few months ago. You should examine 2 options. First look at the groups in your windows not on the sql server and see if aspnet and guest accounts are enabled or disabled. If they are disabled pls make them enabled then delete the available aspnet account in your sql. Create again an aspnet account in your sql choosing available accounts in your windows account, dont create aspnet account by typing aspnet yourself. just choose. Finally as you know, give this account necessary permissions you need to do your work in your database. I hope this will solve the problem :)

The Ghost of PC
[ Peace in country, peace in the world]

|||

Cannot open user default database

The user you set up does not have permissions on the database you set as the users default database.

|||

ghost,

I'm a real newbie. How do I look at groups in my windows? I have the same problem, only with some databases and not others.

dennist685

|||No offense but I kind of guessed that! If you see my message you'll see that I already added the user so that wasn't the problem.

I actually changed the way I connected to the database to:

Data Source=.\SQLEXPRESS;Initial Catalog=myDb;Integrated Security=True;

previously I was using:

Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|myDb.mdf

Now, here's the wiered thing. If I connect using the top method, it works and I'm connecting as machinename/ASPNET.

If I use the second connection string, I'm still connecting as machinename/ASPNET but the login fails.

So, if anyone can explain that, I'd be interested to know why it happens. I've set up machinename/ASPNET as a user so that ISN'T the problem as it lets me connect using the top connection string. It seems to be when I use the bottom method for connecting that I get the error even though I know that machinname/ASPNET is set up as a user on the database.

Wednesday, March 7, 2012

Please Please Help with C# and ASP.net

I am trying to do an inner join on two tables with the following look
Table Name: Event
Event.event_id (primary key)
Event.venue_id
Event.artist_id
Event.date_time
Table Name: Venue
Venue.venue_id
Venue.name
Venue.city
Venue.state
I want to be able to display them but i get an error with the following code
SqlConnection conn = new SqlConnection(connect_string);
string query ="SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state"
+ "FROM Event, Venue WHERE Event.artist_id=" +art_id + "AND Event.venue_id=Venue.venue_id ORDER BY Event.date_timeASC";
SqlCommand cmd = new SqlCommand(query, conn);
SqlDataAdapter adp = new SqlDataAdapter();
adp.SelectCommand = cmd;
DataSet ds = new DataSet();
adp.Fill(ds,"Event"); //Error below falls on this line of code.
foreach (DataRow dr in ds.Tables["Event"].Rows)
{
date_label.Text += dr["Event.date_time"].ToString()+ "<br>";
}
How do i do this join and be able to output the information of the Event.date_time, Venue.city, Venue.name, Venue.state
I get the following error

The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query. The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Event' does not match with a table name or alias name used in the query. The column prefix 'Venue' does not match with a table name or alias name used in the query.


(1) It would look like"
SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state"
+ "FROM Event INNER JOIN Venue ON Event.venue_id=Venue.venue_id WHERE Event.artist_id=@.artId ORDER BY Event.date_timeASC";
(2) Notice I have used @.artId.You should be using parameterized queriesto prevent SQL Injection attack ( a simple google search on this willgive you enough information).
|||Your string:
string query ="SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state"
+ "FROM Event, Venue WHERE Event.artist_id=" +art_id + "AND Event.venue_id=Venue.venue_id ORDER BY Event.date_timeASC";
Should be:
string query ="SELECT Event.date_time, Event.venue_id, Venue.city, Venue.name,Venue.state "
+ "FROM Event, Venue WHERE Event.artist_id=" +art_id + "AND Event.venue_id=Venue.venue_id ORDER BY Event.date_timeASC";
(I added a space at the end of the first line. The "Venue.state" and "FROM" were concatenated)
|||Thanks for pointing that out scampbell12001.

PLEASE PLEASE HELP - How can I get a return value from a SQL Stored Proc is ASP.NET?

Hi. I'm sorry to bother all of you, but I have spent two days looking
at code samples all over the internet, and I can not get a single one
of them to work for me. I am simply trying to get a value returned to
the ASP from a stored procedure. The error I am getting is: Item can
not be found in the collection corresponding to the requested name or
ordinal.

Here is my Stored Procedure code.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
Go
ALTER PROCEDURE [dbo].[sprocRetUPC]
@.sUPC varchar(50),
@.sRetUPC varchar(50) OUTPUT

AS

BEGIN
SET NOCOUNT ON;
SET @.sRetUPC = (SELECT bcdDVD_Title FROM tblBarcodes WHERE bcdUPC =
@.sUPC)
RETURN @.sRetUPC

END

Here is my ASP.NET code.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim oConnSQL As ADODB.Connection

oConnSQL = New ADODB.Connection
oConnSQL.ConnectionString = "DSN=BarcodeSQL"
oConnSQL.Open()

Dim oSproc As ADODB.Command
oSproc = New ADODB.Command
oSproc.ActiveConnection = oConnSQL
oSproc.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
oSproc.CommandText = "sprocRetUPC"

Dim oParam1
Dim oParam2
oParam1 = oSproc.CreateParameter("sRetUPC",
ADODB.DataTypeEnum.adVarChar,
ADODB.ParameterDirectionEnum.adParamOutput, 50)
oParam2 = oSproc.CreateParameter("sUPC", ADODB.DataTypeEnum.adVarChar,
ADODB.ParameterDirectionEnum.adParamInput, 50, "043396005396")

Dim res
res = oSproc("sRetUPC")

Response.Write(res.ToString())

End Sub

If I put the line -
oSproc.Execute()

above the "Dim res" line, I end up with the following error:
Procedure or function 'sprocRetUPC' expects parameter '@.sUPC', which
was not supplied. I thought that oParam2 was the parameter. I was also
under the assumption that the return parameter has to be declared
first. What am I doing wrong here?jbonifacejr wrote:

Quote:

Originally Posted by

>
Hi. I'm sorry to bother all of you, but I have spent two days looking
at code samples all over the internet, and I can not get a single one
of them to work for me. I am simply trying to get a value returned to
the ASP from a stored procedure. The error I am getting is: Item can
not be found in the collection corresponding to the requested name or
ordinal.
>
Here is my Stored Procedure code.
>
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
Go
ALTER PROCEDURE [dbo].[sprocRetUPC]
@.sUPC varchar(50),
@.sRetUPC varchar(50) OUTPUT
>
AS
>
BEGIN
SET NOCOUNT ON;
SET @.sRetUPC = (SELECT bcdDVD_Title FROM tblBarcodes WHERE bcdUPC =
@.sUPC)
RETURN @.sRetUPC
>
END
>
Here is my ASP.NET code.
>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
>
Dim oConnSQL As ADODB.Connection
>
oConnSQL = New ADODB.Connection
oConnSQL.ConnectionString = "DSN=BarcodeSQL"
oConnSQL.Open()
>
Dim oSproc As ADODB.Command
oSproc = New ADODB.Command
oSproc.ActiveConnection = oConnSQL
oSproc.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
oSproc.CommandText = "sprocRetUPC"
>
Dim oParam1
Dim oParam2
oParam1 = oSproc.CreateParameter("sRetUPC",
ADODB.DataTypeEnum.adVarChar,
ADODB.ParameterDirectionEnum.adParamOutput, 50)
oParam2 = oSproc.CreateParameter("sUPC", ADODB.DataTypeEnum.adVarChar,
ADODB.ParameterDirectionEnum.adParamInput, 50, "043396005396")
>
Dim res
res = oSproc("sRetUPC")
>
Response.Write(res.ToString())
>
End Sub
>
If I put the line -
oSproc.Execute()
>
above the "Dim res" line, I end up with the following error:
Procedure or function 'sprocRetUPC' expects parameter '@.sUPC', which
was not supplied. I thought that oParam2 was the parameter. I was also
under the assumption that the return parameter has to be declared
first. What am I doing wrong here?


Just a few pointers here:
- creating a parameter will just create a parameter. To use it, you need
to add it to the command object using oSProc.Parameters.Append
- in a stored procedure you can only use the RETURN keyword to return an
integer, so @.sRetUPC is out of the question
- if you want to use the value of the output parameter, then you should
access it through the Parameters collection of the Command object. The
syntax you are currently using refers to the resultset, but the stored
procedure does not have one

HTH,
Gert-Jan|||Thank you for your help. Any chance you have a moment to help just a
little more? Here is what I did, but I still can't access the value
output by the stored proc...

I removed the Return @.sRetUPC line. I am guessing that I can rely on
the set @.sRetUPC line to set the value of the output parameter

Quote:

Originally Posted by

>From there, I appended the parameters in the ASP code...like this


oSproc.Parameters.Append(oParam2)
oSproc.Parameters.Append(oParam1)
--originally I tried to do Param1 then Param2, but I got an error
about the parameter
--type being an output, so I just figured I had them in the wrong
order because the
--first parameter in the code was the output one.

Then, I added the line oSproc.Execute()
After that is:
Dim res
res = oSproc.Parameters.Item("sRetUPC").Value.toString()

This is not working. Do you know how I can get access to the value of
the parameter that is returned?

Quote:

Originally Posted by

Just a few pointers here:
- creating a parameter will just create a parameter. To use it, you need
to add it to the command object using oSProc.Parameters.Append
- in a stored procedure you can only use the RETURN keyword to return an
integer, so @.sRetUPC is out of the question
- if you want to use the value of the output parameter, then you should
access it through the Parameters collection of the Command object. The
syntax you are currently using refers to the resultset, but the stored
procedure does not have one
>
HTH,
Gert-Jan

|||jbonifacejr (jbonifacejr@.hotmail.com) writes:

Quote:

Originally Posted by

Thank you for your help. Any chance you have a moment to help just a
little more? Here is what I did, but I still can't access the value
output by the stored proc...
>
I removed the Return @.sRetUPC line. I am guessing that I can rely on
the set @.sRetUPC line to set the value of the output parameter
>

Quote:

Originally Posted by

>>From there, I appended the parameters in the ASP code...like this


oSproc.Parameters.Append(oParam2)
oSproc.Parameters.Append(oParam1)
--originally I tried to do Param1 then Param2, but I got an error
about the parameter
--type being an output, so I just figured I had them in the wrong
order because the
--first parameter in the code was the output one.
>
Then, I added the line oSproc.Execute()
After that is:
Dim res
res = oSproc.Parameters.Item("sRetUPC").Value.toString()
>
This is not working. Do you know how I can get access to the value of
the parameter that is returned?


Never say "not working" in newsgroup post with explaining what it
means. Do you get an unexpected result? An error message? Something
else?

Since I don't even know how your code looks like right now, just two
notes:

1) Use parameter names with leading @.. The underlying provider may
prefer that.

2) Use adParamInputOutput for the output value. T-SQL does not have any
true output-only parameters. (Save the return value, but there is a
separate enum value for return values as I recall.)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||If you look at the top post you will see where I put the code I am
using. I also tried to let people know what happened when I tried their
suggestions. But, thanks for the advice...and I'll look at those SQL
Books online.

Jan

Erland Sommarskog wrote:

Quote:

Originally Posted by

jbonifacejr (jbonifacejr@.hotmail.com) writes:

Quote:

Originally Posted by

Thank you for your help. Any chance you have a moment to help just a
little more? Here is what I did, but I still can't access the value
output by the stored proc...

I removed the Return @.sRetUPC line. I am guessing that I can rely on
the set @.sRetUPC line to set the value of the output parameter

Quote:

Originally Posted by

>From there, I appended the parameters in the ASP code...like this


oSproc.Parameters.Append(oParam2)
oSproc.Parameters.Append(oParam1)
--originally I tried to do Param1 then Param2, but I got an error
about the parameter
--type being an output, so I just figured I had them in the wrong
order because the
--first parameter in the code was the output one.

Then, I added the line oSproc.Execute()
After that is:
Dim res
res = oSproc.Parameters.Item("sRetUPC").Value.toString()

This is not working. Do you know how I can get access to the value of
the parameter that is returned?


>
Never say "not working" in newsgroup post with explaining what it
means. Do you get an unexpected result? An error message? Something
else?
>
Since I don't even know how your code looks like right now, just two
notes:
>
1) Use parameter names with leading @.. The underlying provider may
prefer that.
>
2) Use adParamInputOutput for the output value. T-SQL does not have any
true output-only parameters. (Save the return value, but there is a
separate enum value for return values as I recall.)
>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||Why are you using stored proc when you can use a function(s)? I always
thought the output parameter was a bit of a hack and clumsy to use.

jbonifacejr wrote:

Quote:

Originally Posted by

If you look at the top post you will see where I put the code I am
using. I also tried to let people know what happened when I tried their
suggestions. But, thanks for the advice...and I'll look at those SQL
Books online.
>
Jan
>
Erland Sommarskog wrote:

Quote:

Originally Posted by

jbonifacejr (jbonifacejr@.hotmail.com) writes:

Quote:

Originally Posted by

Thank you for your help. Any chance you have a moment to help just a
little more? Here is what I did, but I still can't access the value
output by the stored proc...
>
I removed the Return @.sRetUPC line. I am guessing that I can rely on
the set @.sRetUPC line to set the value of the output parameter
>
>>From there, I appended the parameters in the ASP code...like this
oSproc.Parameters.Append(oParam2)
oSproc.Parameters.Append(oParam1)
--originally I tried to do Param1 then Param2, but I got an error
about the parameter
--type being an output, so I just figured I had them in the wrong
order because the
--first parameter in the code was the output one.
>
Then, I added the line oSproc.Execute()
After that is:
Dim res
res = oSproc.Parameters.Item("sRetUPC").Value.toString()
>
This is not working. Do you know how I can get access to the value of
the parameter that is returned?


Never say "not working" in newsgroup post with explaining what it
means. Do you get an unexpected result? An error message? Something
else?

Since I don't even know how your code looks like right now, just two
notes:

1) Use parameter names with leading @.. The underlying provider may
prefer that.

2) Use adParamInputOutput for the output value. T-SQL does not have any
true output-only parameters. (Save the return value, but there is a
separate enum value for return values as I recall.)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||jbonifacejr (jbonifacejr@.hotmail.com) writes:

Quote:

Originally Posted by

If you look at the top post you will see where I put the code I am
using.


Since then you changed the code according to Gert-Jan's advice, and we
don't know what it looked after that.

Basically, if you only say "not working" without specifying why, and
don't show us the code, don't expect that much help. But that's your call.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Thanks Erland...I see where I screwed up. I thought I had explained
what was wrong, but I did that in a different thread in another forum.

Anyway, I got this working using classic ASP and ADODB. Now I am going
to try to get it working over ASP.NET and ADO.NET. Wish me luck.

So far, eveerything works except that I am constantly being told that
the stored procedure expects a parameter that was not supplied.
However, The same two parameters are created and added to the
Parameters of the command object.

I'll continue to work on it and see if I can get it to work. Looks like
I need a datareader or some other object. I found a great KB article
that basically shows me everythig I am doing (right and wrong)...

http://support.microsoft.com/kb/306574
Erland Sommarskog wrote:

Quote:

Originally Posted by

jbonifacejr (jbonifacejr@.hotmail.com) writes:

Quote:

Originally Posted by

If you look at the top post you will see where I put the code I am
using.


>
Since then you changed the code according to Gert-Jan's advice, and we
don't know what it looked after that.
>
Basically, if you only say "not working" without specifying why, and
don't show us the code, don't expect that much help. But that's your call.
>
>
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||jbonifacejr (jbonifacejr@.hotmail.com) writes:

Quote:

Originally Posted by

Thanks Erland...I see where I screwed up. I thought I had explained
what was wrong, but I did that in a different thread in another forum.


Posting the same question independently to two forums is not a nice
thing to. This means that people can waste time on answering your post,
when it has already been answered elsewhere.

Quote:

Originally Posted by

Anyway, I got this working using classic ASP and ADODB. Now I am going
to try to get it working over ASP.NET and ADO.NET. Wish me luck.
>
So far, eveerything works except that I am constantly being told that
the stored procedure expects a parameter that was not supplied.
However, The same two parameters are created and added to the
Parameters of the command object.


Again, without seeing your code it's hard to tell. There is a difference
between ADO and SqlClient though: with ADO, the parameter names are
just local to the application, so if you misspell a parameter name,
you may get away with it. Not so with SqlClient.

Quote:

Originally Posted by

I'll continue to work on it and see if I can get it to work. Looks like
I need a datareader or some other object.


Since your procedure has an output parameter, but no result set, the most
conventient method to use is ExecuteNonQuery, in which case you only need
the Command object.
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx