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
 General SQL Server Forums
 New to SQL Server Programming
 connect with sql server 2005

Author  Topic 

adya
Starting Member

31 Posts

Posted - 2008-09-22 : 12:41:47
I am trying to connect asp.net 3.5 page with the database in sql server 2005.

I have used the following connection string in web.config:
<appSettings>
<add key="ConnectionString" value="Server=localhost;Database=RLMS-ageis;Integrated Security=true" />
</appSettings>

and in the pages, I am using:
String connectionString = WebConfigurationManager.ConnectionStrings["RLMS-ageis"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.open();

Can you please tell me where i am wrong.

Thanks!


Adya

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-22 : 12:56:23
This should have been posted in the .net forum

http://www.sqlteam.com/forums/forum.asp?FORUM_ID=17


More like

WEBCONFIG

<connectionStrings>
<add name="My_ConnectionString" connectionString="Data Source=xx.xx.xxx.xxx,2433;Network Library=DBMSSOCN;Initial Catalog=Mydatabase;User ID=username;Password=password;" providerName="System.Data.SqlClient"/>
</connectionStrings>



For more details on your connection string see www.connectionstrings.com




CLASS
Am not sure from your code if you are running a SP or what ? But try this


Dont forget to declare your SQL namespace

using System.Data.SqlClient;

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["My_ConnectionString"].ConnectionString.ToString());
SqlCommand command = new SqlCommand("SP_Name", con);
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 20;

con.Open();
Go to Top of Page

adya
Starting Member

31 Posts

Posted - 2008-09-22 : 15:37:20
thanx!!!

will make d changes...
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-22 : 16:06:01
Glad2help
Go to Top of Page
   

- Advertisement -