WebConfig.
<connectionStrings> <clear/> <add name="LocalTestSqlServer" connectionString="Data Source=CHARITH; Initial Catalog=Test; User ID={0}; Password={1}"/> </connectionStrings>
Consuming Page:
<%@ Page Language="C#" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <script runat="server"> protected void SetCredentials(object sender, EventArgs e) { SqlDataSource sdt = sender as SqlDataSource; sdt.ConnectionString = string.Format(sdt.ConnectionString, "UserName", "Password"); } </script> </head> <body> <form id="form1" runat="server"> <asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:LocalSqlServer %>" ID="SqlDataSource2" OnInit="SetCredentials" runat="server" /> </form> </body> </html>
2 comments:
Thanks very much! I was looking for another way to do this and also found this solution:
http://deepinthecode.com/2012/05/24/dynamically-set-connectionstring-on-sqldatasource-asp-net-control/
Perfect !!!!!!!!
Thanks.
Evandro
Post a Comment