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
 connection string

Author  Topic 

Mpilo
Yak Posting Veteran

52 Posts

Posted - 2008-09-25 : 07:21:21
hi there

how do i put the connection using password and username in my application using 3 tier
im coding using C# and sql server platform.plz can you provide me with sample data???

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 07:26:39
http://msdn.microsoft.com/en-us/library/aa581776.aspx
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-25 : 11:20:11
hi Mpilo,
put your connection in your connection string in your web.config file and reference it with the variable name. e.g.

Here is an example that takes one variable "variable_name" from a class called classname. Hope this helps


<connectionStrings>
<add name="Mpilo" connectionString="Data Source=00.111.123.877,2433;Network Library=DBMSSOCN;Initial Catalog=mpilos_Database_name;User ID=mpilos;Password=mpilospassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>




And in your class


public class classname
{
public classname(string variable_name)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Mpilo"].ConnectionString.ToString());


SqlCommand command = new SqlCommand("SP_Name", con);
command.CommandType = CommandType.StoredProcedure;
command.CommandTimeout = 20;

con.Open();

command.Parameters.Add(new SqlParameter("@example", SqlDbType.VarChar, 200, "variable_name"));

command.Parameters[0].Value = variable_name;
int i = command.ExecuteNonQuery();


con.Close();


And in your code behind aspx.cs class, you can call the class as thus

classname newclass = classname(variable_name);
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-09-25 : 11:57:00
Also next time, post your .net questions in the .net forum.

These are MS SQL forums, it will help to get your answers answered without confusion.

http://www.sqlteam.com/forums/forum.asp?FORUM_ID=17
Go to Top of Page
   

- Advertisement -