Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 connect with sql

Author  Topic 

adya
Starting Member

31 Posts

Posted - 2008-09-23 : 11:43:34
I am new to asp.net, and am creating a website. I am stuck at this point.

I have set up a data connection, using the database and i can see all the tables, stored procedures etc. in the server explorer.

But, when i try to use the asp.net web site administrator tool, it gives me an error: Cannot open database "RLMS-ageis" requested by the login. The login failed. Login failed for user 'workstation001\adya'.

Am i missing something?

Thanks in advance!

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-23 : 11:52:32
Post your connection string here or your code behind.
Go to Top of Page

adya
Starting Member

31 Posts

Posted - 2008-09-23 : 12:03:15
thats the connection string i am using:

<connectionStrings>

<add name="RLMS-ageis" connectionString="Data Source=workstation001\SQLEXPRESS;Initial Catalog=RLMS-ageis;Trusted_Connection=True;" />

</connectionStrings>
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-23 : 12:10:17
Try this

<add name="RLMS-ageis" connectionString="Data Source=workstation001\SQLEXPRESS;Initial Catalog=RLMS-ageis;Trusted_Connection=True;" providerName="System.Data.SqlClient" />


Also pls post your connection in your code behind

... as
quote:
Cannot open database "RLMS-ageis" requested by the login

is not your database, but your connection name
Go to Top of Page

adya
Starting Member

31 Posts

Posted - 2008-09-23 : 12:25:59
Sorry, I dont understand connection in your code behind...
wat do you want?

Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-23 : 12:34:24
something like this


SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString.ToString());


SqlCommand command = new SqlCommand("Sp_billing", con);
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 20;
Go to Top of Page

adya
Starting Member

31 Posts

Posted - 2008-09-23 : 12:39:59
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RLMS-ageis"].ConnectionString.ToString());
SqlCommand command = new SqlCommand("name", con);
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 20;

Please tell me the basic procedure(as in numbered steps) to connect to the SQL Server database in asp.net 3.5 and then how to access the database, say for updating values in tables. I have looked at various tutorials and videos and am unable to understand it.

Thanks

Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-23 : 13:15:57
NOthing wrong with your code.

The error message above says login failed for user 'workstation001\adya'

Confirm that your database instance you are trying to access is workstation001\SQLEXPRESS and its a trusted connection
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-23 : 13:23:40
Also did you create a database user and grant him login permissions to your database ?
Go to Top of Page

Matt2k9
Starting Member

10 Posts

Posted - 2008-09-24 : 06:08:39
If you are using sql express i.e. the database is a local instance on the same machine as the application, your connection string should also contain User Instance=True, as this is an instance of sql 2005 database, which sql server 2005 and asp.net treats differently. I THINK, this might cause sql to grant the login without you having to run grant_login sp on the db itself, because you are telling it that it's an instance database. But I cannot remember for sure as I only use remote sql db's, even so, you should definately have this in there. You should also clear out before the connection string in web.config:

<connectionstrings>
<clear/>
<add name..

Secondly, if the above does not work, you should ensure that your database is actually allowing your application to login - as afrika suggests. You could do this by running sql server profiler from sql server management studio express. if the login is failing you will see this in red in sql server profiler. Then you will know for sure that this is a sql server permissions issue not an asp.net issue.

Third, once you fix this I would not bother with the admin tool, you get a much finer grained control by learning how to edit the web.config file manually - which is what the tool does anyway. When you go live, you will not be able to use the admin tool and will have to learn how to do this anyway!! The syntax is very very easy and you can learn it by visiting asp.net/learn and checking out some short videos.
Go to Top of Page

adya
Starting Member

31 Posts

Posted - 2008-09-24 : 15:06:18
Thanks!

I can now access the database. I ran the aspnet_reqsql, the error didnt come up again.


Adya
Go to Top of Page
   

- Advertisement -