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.
Author |
Topic |
wallfreshers
Starting Member
2 Posts |
Posted - 2012-04-24 : 09:43:46
|
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-csBUT 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; } |
|
|
|
|