Tuesday, March 20, 2012

Cannot open database requested in login ?!(help me ! )

Hi
I'm new in using "SqlClient" I have SQLSERVER 2000 on my computer and I made a Database named "TestDB", and a code like this both Using VS.net :

// begin test Code ///////////////////////////////////
string connectionString =
"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog= TestDB;Data Source=HOSSEIN-COM;Workstation ID=HOSSEIN-COM";
string commandString =
"Select * from Categories";
SqlDataAdapter DataAdapter =
new SqlDataAdapter(
commandString, connectionString);
DataSet DataSet = new DataSet( );
DataAdapter.Fill(DataSet,"CategoryID");
Label1.Text= DataSet.Tables[0].Rows[0]["CategoryID"].ToString();

// end test code /////////////////////////////////////

And at browser I found this error when I Start Building the project:

"Cannot open database requested in login 'testdb'. Login fails. Login failed for user '(my coputer name / my name )' "

Then I changed Catalog= TestDB to Catalog= Northwind and the table name to and available table name and it works , then I tried to create a table at northwind database but this error appeared :
"SELECT permission denied on object 'testTB', database 'Northwind', owner 'dbo'"
TestTB = my northwind table
I guess there must be some security setting in creating databases and tables that I do not know , And when I tried to install quick start the database was not installed ,
I have XP and VS.net and SQLserver 2000 . please halp me as You always do ;) …you need to add the user machinename/ASPNET to the db and also give select permissions to this user on the tables.

hth

No comments:

Post a Comment