Showing posts with label details. Show all posts
Showing posts with label details. Show all posts

Monday, March 12, 2012

Login Error

Hi

I am using MSDE2000 and ASP.NET. I have 3 data adapters and a dataset. When running the program I get:

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'CGREGORYT2XP\ASPNET'.

Source Error:
Line 257: If Not Page.IsPostBack Then
Line 258:
Line 259: SqlConnection1.Open()
Line 260:
Line 261: SqlDataAdapter1.Fill(Ds1, "employee")

I have used sp_grantdbaccess 'machinename\ASPNET' on PUBS but still get error.

Where am I going wrong??

Thanks

I pressume you have added a user to the SQL Server for CGREGORYT2XP\ASPNET and that the SQL server supports Mixed Mode authentication.

If not check you have a user by selecting "Security", "Logins" in Enterprise Manager you should see a user in the list called CGREGORYT2XP\ASPNET.

Friday, February 24, 2012

Logic statement using select query

I'd like to make a logic statement, that would take as arguments result of the sql select query. In more details: I would like to create a local Bool variable that would be false if some value is NULL in the table (or select query).

Query example:

select taskID from Users where Login=@.username

Which classes/methods should i use to solve this problem? I use SqlDataSource to get access to database and i think i should use something like SqlDataSource.UpdateCommand and SqlDataSource.UpdateParameters but dont know how to build from this a logic statement.

Thanks in advance

If you are using the SqlDataSource, in its Selected event, you can check the RowsAffected property. If it is > 0, set your bool to true:

bool Check = False;

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
int RecordCount = e.AffectedRows;

if (RecordCount > 0)
{ Check = True; }
}


|||

Actually I tried to make it in the Page_Load(object sender, EventArgs e) event. Does it change anything?

I'm wondering if there is a way to get to sql query from C# code. Something like:

[for each row from select query]

bool present;

if ( [row.taskID] == null )

{

present = false;

}

|||You will not get rows containing null from the query you showed in your example. You will only get rows that contain the TaskID that belong to the user specified. If there are no TaskIDs for that user, you will get no rows at all.|||

I think i will get a row of some user even if he has NULL in taskID field. I checked this and i got the row that i wanted with empty value of the taskID field.

But even if there would be e.g. -1 the problem still exists and i have no idea how to solve it or even where to look for solution.

|||I beg your pardon. You are right. I didn't read your query correctly. You can access values from a datasource as described here:http://www.mikesdotnetting.com/Article.aspx?ArticleID=45, and check each value, setting your bool accordingly|||

Thaks again, it works fine now. You are gosu ;)

|||

DCVer:

You are gosu ;)

Is that a good thing?Confused

|||

Yes, you are master, the king etcSmile

Logging Usage (logins)?

Hi everyone!

Can anyone tell me if it's possible to set up some kind of a trigger that will write out to a file or a table and log details of all database connections?
ie: user, datetime of connection, database connected to, etc.

Any help appreciated.

Cheers,
MeganHi Meagan ,

Use SQL Profiler and run a trace you will then see which user connected to which database and at which time they did so ...and more.

Regards
Burner