SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 Managed Function Connection String
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wallfreshers
Starting Member

India
2 Posts

Posted - 04/24/2012 :  09:43:46  Show Profile  Reply with Quote
THE CONNECTION STRING IN THE FOLLOWING CODE IS DIFFERENT FROM THE ONE WE USED WHILE CREATING SQL PROJECT IN VISUAL STUDIO, THE STEP BY STEP PROCEDURE IS IN THE FOLLOWING LINK http://www.asp.net/web-forms/tutorials/data-access/advanced-data-access-scenarios/creating-stored-procedures-and-user-defined-functions-with-managed-code-cs

BUT THE CODE WORKS WHEN SqlConnection con = new SqlConnection("context connection=true"); BUT WHEN WE MANUALLY SPECIFY CONNECTION STRING IT DOES NOT WORK. PLEASE HELP

public static SqlString Function1(int SubmenuID, string table)
{

// Put your code here
string URL = "";
//SqlConnection con = new SqlConnection("context connection=true");

SqlConnection con = new SqlConnection();

//"Data Source=PM\\SQLEXPRESS; Initial Catalog=LawSuit; uid=sa; pwd=walgreens123#; Connect Timeout=60;Min Pool Size=5;Max Pool Size=60;");
con.ConnectionString = "Data Source=WLGRN-5\\SQLEXPRESS; Initial Catalog=LAWSUIT_TRANS_17_04-2012; uid=sa; pwd=walgreens123#; Connect Timeout=60;Min Pool Size=5;Max Pool Size=60;";
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
string str = @"select (select Url From " + table + " s inner join UserGroupLine l on l.refMenuID=s.RefMenuID where RefSubMenuID=" + SubmenuID + " and NewEdit=1 and (IsEdit=1 or IsView=1) )";

cmd.CommandText = str;
cmd.Parameters.AddWithValue("@SubMenuID", SubmenuID);
cmd.Parameters.AddWithValue("@tbl", table);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows && dr.Read())
{
URL = dr.GetString(0);
}

return URL;

}
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000