Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: problem in connecting to sql server.


Message #1 by "Raajesh.P" <rajeshp@b...> on Wed, 3 Jul 2002 07:43:19
Hi,

This example is from microsoft site and i have changed the server name 
alone. But it errors SQL Server does not exist or access denied.

And I even tried with other databases in my server by giving user ID and 
password,still same problem comes to me but The Asp version works fine.

Help me to trace the problem.

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>
<script language="VB" runat="server">

    Sub Page_Load(Sender As Object, E As EventArgs)

        Dim MyConnection As SqlConnection = New SqlConnection
("server=Cosmos;database=pubs;Trusted_Connection=yes")
        Dim MyCommand As SqlCommand = New SqlCommand("select * from 
Authors", MyConnection)

        MyConnection.Open()

        Dim dr As SqlDataReader = MyCommand.ExecuteReader()

        MyDataGrid.DataSource = dr
        MyDataGrid.DataBind()

        MyConnection.Close()
    End Sub

</script>

<body>

  <h3><font face="Verdana">Simple Select to a DataGrid Control</font></h3>

  <ASP:DataGrid id="MyDataGrid" runat="server"
    Width="700"
    BackColor="#ccccff"
    BorderColor="black"
    ShowFooter="false"
    CellPadding=3
    CellSpacing="0"
    Font-Name="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#aaaadd"
    EnableViewState="false"
  />

</body>
</html>

Thanks

P.Raajesh
Message #2 by "Carole D Sullivan" <carolesullivan@e...> on Mon, 8 Jul 2002 16:58:14
When I have connection problem it is usually because I forgot to give 
the "annonymous user" (MACHINENAME/ASPNET) the right to access the tables 
in SQL Server or execute permission on the stored procedure has not been 
granted.  

ASP and ASP.NET use different 'users' in SQL.  ASP.NET uses the format 
above and ASP pages use the IUSR_MACHINENAME.  

If you install the Microsoft ispy.com application, you can use there app 
as reference; because it installs everything in your system including SQL 
Server tables, stored procedure etc, you can check out what they did.  

Carole

> 
H> i,

> This example is from microsoft site and i have changed the server name 
a> lone. But it errors SQL Server does not exist or access denied.

> And I even tried with other databases in my server by giving user ID and 
p> assword,still same problem comes to me but The Asp version works fine.

> Help me to trace the problem.

> <%@ Import Namespace="System.Data" %>
<> %@ Import Namespace="System.Data.SqlClient" %>

> <html>
<> script language="VB" runat="server">

>     Sub Page_Load(Sender As Object, E As EventArgs)

>         Dim MyConnection As SqlConnection = New SqlConnection
(> "server=Cosmos;database=pubs;Trusted_Connection=yes")
 >        Dim MyCommand As SqlCommand = New SqlCommand("select * from 
A> uthors", MyConnection)

>         MyConnection.Open()

>         Dim dr As SqlDataReader = MyCommand.ExecuteReader()

>         MyDataGrid.DataSource = dr
 >        MyDataGrid.DataBind()

>         MyConnection.Close()
 >    End Sub

> </script>

> <body>

>   <h3><font face="Verdana">Simple Select to a DataGrid 
Control</font></h3>

>   <ASP:DataGrid id="MyDataGrid" runat="server"
 >    Width="700"
 >    BackColor="#ccccff"
 >    BorderColor="black"
 >    ShowFooter="false"
 >    CellPadding=3
 >    CellSpacing="0"
 >    Font-Name="Verdana"
 >    Font-Size="8pt"
 >    HeaderStyle-BackColor="#aaaadd"
 >    EnableViewState="false"
 >  />

> </body>
<> /html>

> Thanks

> P.Raajesh
Message #3 by "Mitesh" <mitesh_bilimoria@y...> on Mon, 8 Jul 2002 20:24:55
your connection string would be something like this:::

data source=ServerName;initial 
catalog=DatabaseName;password=Password;persist security info=True;user 
id=username;

Mitesh

  Return to Index