PDA

View Full Version : connecting to remote data base


saly
12-23-2010, 01:23 AM
Can any one send me to the correct path to do connection to data base hosted in a remote server using C#.net. I'd like to try it before hosting my entire website if it worked , very good I will enhance my hosting procedure further.
I will be a great appreciate for helping me
tnx

wisemx
12-23-2010, 03:58 AM
Sure...
This is a valid web.config connection string and a C-Sharp page using it:

<connectionStrings>
<clear />
<add name="SharpConnString" connectionString="Data Source=tcp:sql2k8.discountasp.net;Persist Security Info=True;User ID=SQL2008_wisemx_user;Password=MakeaWish"
providerName="System.Data.SqlClient" />
</connectionStrings>

----------------------------------------------

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SQL2008_msftwise_userConnectionS tring %>"
SelectCommand="SELECT DISTINCT * FROM [comments]"></asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333">
<AlternatingItemStyle BackColor="White" ForeColor="#284775" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="#F7F6F3" ForeColor="#333333" />
<ItemTemplate>
key:
<asp:Label ID="keyLabel" runat="server" Text='<%# Eval("key") %>' />
<br />
ip:
<asp:Label ID="ipLabel" runat="server" Text='<%# Eval("ip") %>' />
<br />
dated:
<asp:Label ID="datedLabel" runat="server" Text='<%# Eval("dated") %>' />
<br />
said:
<asp:Label ID="saidLabel" runat="server" Text='<%# Eval("said") %>' />
<br />
<br />
</ItemTemplate>
<SelectedItemStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:DataList>

</div>
</form>
</body>
</html>