Showing posts with label sqlexpress. Show all posts
Showing posts with label sqlexpress. Show all posts

Thursday, March 22, 2012

Authentication not working!

Hey there,

I have a table [user] in a SQLExpress database [Database.mdf] in the App_Data folder. There are two columns. [userId] and [password]. I want to authenticate the user who wants to log in through a Login control. the user should have his userId and password in the [user] table. I digged and made my code. but it doesn't work it keeps giving me that the user is not authenticated. i guess it has no errors. please tell me if you find the error. here is the code:

1protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)2 {3 SqlConnection conExpress =new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True;User Instance=False");//Create the server connection45try6 {7string id_user = Login1.UserName.Trim();//Get the username from the control8string pass_user = Login1.Password;//get the Password from the control910 //These are a sql and connection Examples11string sql ="SELECT userId, password FROM user WHERE userId = @.param_Id AND password = @.param_Password";12 SqlCommand comSQL =new SqlCommand(sql, conExpress);//Create the sql command using sql string and sql connection1314 //Add the sql parameters15 comSQL.Parameters.AddWithValue("@.param_Id", id_user);//New on VS 2.016 comSQL.Parameters.AddWithValue("@.param_Password", pass_user);1718string cod_user ="";19string name_user ="";2021//Open database connection22 conExpress.Open();23 SqlDataReader dr = comSQL.ExecuteReader();24while (dr.Read())25 {26 cod_user = dr.GetValue(0).ToString();//The coduser is unique onto database table27 name_user = dr.GetValue(1).ToString();28 }29 conExpress.Close();//Close Database Connection30if (cod_user !="")//The user exist onto database31 {32//Create the session vars33 Session["coduser"] = cod_user;34 Session["nameuser"] = name_user;35 e.Authenticated =true;//Grant the access, Goes to DestinationPageUrl36 }37 }38catch(Exception)//On Login Error39 {40 e.Authenticated =false;//Confirm that you are out41 conExpress.Close();//On any error case, close the database connection42 }43 }

The way I've used the Login control with custom authentication (without MembershipProvider) is

processing the event of the Login Control:

protected

void Login1_LoggingIn(object sender,LoginCancelEventArgs e)

and if the credentials is valid i create the autheentication cookie:

FormsAuthentication.SetAuthCookie(userName,false);

and Redirect to the page user has requested.

If the credentials are wrong I set :

e.Cancel =

true;

and

Login1.FailureText =

"Unable to validate credentials";

I'm not sure this is the right way of doing that, but it works for me.

Hope this will help you.

Cheers,

Yani

sql

Sunday, February 12, 2012

Attached DB not working properly in Vista Ultimate enviroment

hi,

i have installed SQLEXPRESS (SQL Server 9.0.3042) on my windows ultimate laptop. of late am facing this issue of database. this database is from SQl 7.0 Desktop edition(the one that i use in my office machine with Xp SP2). As such it works fine in SQL 2000 server after attachment (for test).

i have run SQLEXPRESS as administrator to make/attach new database. i can attach the database easily and can even view tables and other stuffs inside database in administrator mode. the issue pops up when i run SQLEXPRESS in normal mode. when i try to open and view the same DB's content, error pops up stating

"The database XXX is not accessible. (Micorosoft.sqlserver.express.objectExplorer)"

i cannot access this DB via VB 6 form as it dosnt show up at all in database list when tried to connect via ADODC.

i want to make this DB accessibility as normal operation, not previliged only to administrator as application run on normal mode only.

the issue dosnt arise when i locally make a new database as it can be accessed when run in normal mode also. why does this happen to database that is attached and not to ones locally made.

pls guide me as i usually do my works at home and making whole database again will surely take lots of pain. why not it just attach then start working, not asking for preveliged mode.

thanks in adv
Nyaken

Hi,

Try checking the owner of the attached database. I found that when i restored a db I had to then set the ownership afferwards otherwise I couldn't access it.

Chris

|||

hi,

thanks for the prompt re. well, as per ur suggestion i have explored all possibiliites to find a way to change the ownership of database but alas!!! i just couldnt make it. can you pls guide me to take this corrective measure, please. i hope everything must be done in administrative mode only, isnt it?

awaiting for your re

regs

ken

|||

Hi,

If you right click on the attached database and select properties then go the the files page, you should see that the second text box down (the owner field) is blank. If so, set an owner by clicking the elipsis next to the box. After you have clicked all the ok's you can check the owner was set by going back to the files page, and if the box now is not empty then the owner was set. You should be able to use the database now.

Hope this helps,

Chris

P.s. I did try to post this yesterday several times but the forum kept giving me an "unkown error"

AttachDbFilename, |DataDirectory| and SQL Server 2005 June CTP Relative Paths

Hello,

I am using "AttachDbFilename" to connect to a June CTP SQLExpress database. I have a windows forms application that has the following connection string (which works fine at the moment):

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|test.mdf';Integrated Security=True;User Instance=True"

However, I would like to make my connection string:

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|..\..\Database\test.mdf';Integrated Security=True;User Instance=True"

But no matter what combination I try (including not using DataDirectory at all), I cannot seem to open the database using the relative path.

Can someone please assist/clarify?

Thanks,
Sean H.

Hi,

DataDirectory is specifically restricted to only allow access to files in the directory pointed to by the DataDirectory value or any of its subdirectories, but not directories up in the chain.

This is to prevent security issues such as those common in older web servers where you could navigate the server file-system by doing something like http://www.mywebsite.com/..\..\..\etc\passwords

-pablo|||When you say "the directory pointed to by the DataDirectory value " what exactly is that? In other words, what is this value and where can I set/change it?

Thanks - Daniel|||

you can change:

AppDomain.CurrentDomain.setData(“DataDirectory”,”C:\newPath\”);

AttachDbFilename, |DataDirectory| and SQL Server 2005 June CTP Relative Paths

Hello,

I am using "AttachDbFilename" to connect to a June CTP SQLExpress database. I have a windows forms application that has the following connection string (which works fine at the moment):

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|test.mdf';Integrated Security=True;User Instance=True"

However, I would like to make my connection string:

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|..\..\Database\test.mdf';Integrated Security=True;User Instance=True"

But no matter what combination I try (including not using DataDirectory at all), I cannot seem to open the database using the relative path.

Can someone please assist/clarify?

Thanks,
Sean H.

Hi,

DataDirectory is specifically restricted to only allow access to files in the directory pointed to by the DataDirectory value or any of its subdirectories, but not directories up in the chain.

This is to prevent security issues such as those common in older web servers where you could navigate the server file-system by doing something like http://www.mywebsite.com/..\..\..\etc\passwords

-pablo|||When you say "the directory pointed to by the DataDirectory value " what exactly is that? In other words, what is this value and where can I set/change it?

Thanks - Daniel|||

you can change:

AppDomain.CurrentDomain.setData(“DataDirectory”,”C:\newPath\”);

AttachDbFilename, |DataDirectory| and SQL Server 2005 June CTP Relative Paths

Hello,

I am using "AttachDbFilename" to connect to a June CTP SQLExpress database. I have a windows forms application that has the following connection string (which works fine at the moment):

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|test.mdf';Integrated Security=True;User Instance=True"

However, I would like to make my connection string:

"Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|..\..\Database\test.mdf';Integrated Security=True;User Instance=True"

But no matter what combination I try (including not using DataDirectory at all), I cannot seem to open the database using the relative path.

Can someone please assist/clarify?

Thanks,
Sean H.

Hi,

DataDirectory is specifically restricted to only allow access to files in the directory pointed to by the DataDirectory value or any of its subdirectories, but not directories up in the chain.

This is to prevent security issues such as those common in older web servers where you could navigate the server file-system by doing something like http://www.mywebsite.com/..\..\..\etc\passwords

-pablo|||When you say "the directory pointed to by the DataDirectory value " what exactly is that? In other words, what is this value and where can I set/change it?

Thanks - Daniel|||

you can change:

AppDomain.CurrentDomain.setData(“DataDirectory”,”C:\newPath\”);

AttachDBFileName - refers to previous log file

Hello,
I'm using the AttachDBFilename option in the SQL connection string to attach
a database to a SQLExpress instance on another machine.
The is an error though, it seems to want to refer to a log file on the
machine the .mdf was originally created on. The error is as follows:
Could not attach file 'C:\Program Files\Strategic Systems\Time
Master\TimeMasterDat.mdf' as database 'TimeMaster'.
File activation failure. The physical file name "D:\Visual Studio 2005
Projects\Strategic\Applications\TimeMaster\Databas e\Strategic.TimeMaster.Database.SQL2005\TimeMaster Dat_log.LDF" may be incorrect
How can I get the attach to avoid referring to this log file?
Answered in
http://forums.microsoft.com/forums/ShowPost.aspx?PostID=1081110&SiteID=1
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de

AttachDBFileName - refers to previous log file

Hello,
I'm using the AttachDBFilename option in the SQL connection string to attach
a database to a SQLExpress instance on another machine.
The is an error though, it seems to want to refer to a log file on the
machine the .mdf was originally created on. The error is as follows:
Could not attach file 'C:\Program Files\Strategic Systems\Time
Master\TimeMasterDat.mdf' as database 'TimeMaster'.
File activation failure. The physical file name "D:\Visual Studio 2005
Projects\Strategic\Applications\TimeMast
er\Database\Strategic.TimeMaster.Dat
abase.SQL2005\TimeMasterDat_log.LDF" may be incorrect
How can I get the attach to avoid referring to this log file?Answered in
http://forums.microsoft.com/forums/...081110&SiteID=1
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
--