Friday, March 23, 2012

How many ways to connect to a database?

How many ways are there to connect to a database in ASP.NET? Could someone list them in a 1,2,3... manner.

For those who are going to ask why I want to know this and why I don't do one way, I'll explain after I get the answer.Smile

http://msdn2.microsoft.com/en-us/library/ms178371.aspx

HTH,

Suprotim Agarwal

|||

Thanks for reply.

I tried to creat a sqldatasource according to that page so I modified config file and added this:

<connectionStrings>
<add name="linksConnectionString" connectionString=" Server=local;Database=mahmood_links;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
</connectionStrings>

and put this line on my aspx page:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:linksConnectionString %>"
SelectCommand="SELECT * FROM [link]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="URL" HeaderText="URL" SortExpression="URL" />
<asp:BoundField DataField="TITLE" HeaderText="TITLE" SortExpression="TITLE" />
</Columns>
</asp:GridView>

But when I ran the file got lots of line of error, these are the first lines of error:

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

what could be the problem then?

|||

Dear mahmood,

Do you have Sql Server 2005 sp2 installed on your computer. Kindly install that and see if that solves your problem.

After having done that, if the problem still persists, you can checkthis link.

HTH,

Suprotim Agarwal

|||

Thanks for replies.

I found out that I needed this connectionstring for the server

Server=localhost;uid=myId;pwd=myPass;database=myDataBase

sql

No comments:

Post a Comment