Eiffel For ASP.NET - SQL Server Example

First, let me introduce myself. I am a web developer and I've been using ASP.NET since 2001. I've only started to learn ASP.NET 2.0 and only started using Visual Studio 2005 this year. I am currently converting an ASP web application to ASP.NET 2.0. I have extensive technology notes which I maintain in a custom help collection integrated in the Microsoft Document Explorer. I've never worked with any other developers so nobody has ever benefited from my experience or seen my notes. I hope to share some of this material here.

 Eiffel is a programming language with some interesting features like design by contract which I won't attempt to describe. Eiffel software provides a CodeDom Provider for writing ASP.NET pages in Eiffel which is available for download for free on the Eiffel Software web site. There is very little sample code to be found on the Internet for using Eiffel with ASP.NET so I will share my sample code for a SQL Server database connection:

 

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>Eiffel - SQL Server Database Connection</title>
<script runat="server">
   indexing
      description: "Connects to a SQL Server database using Eiffel for ASP.NET"
</script>
<script runat="server">
   inherit
      WEB_PAGE
         redefine
            on_load
         end
</script>
<script language="Eiffel" runat=server>
         on_load (e: EVENT_ARGS) is
               -- Initialize values
            local
               connection: DATA_SQL_CONNECTION
               command: DATA_SQL_COMMAND
               reader: DATA_SQL_DATA_READER
               ok: BOOLEAN
               data_string: STRING
            do
               if not is_post_back then
                  create data_string.make(1)
                  create connection.make ("server=SERVER_NAME;uid=***;pwd=***;database=Books")
                  create command.make("SELECT * FROM Books WHERE Author = 'Anne Rice'",connection)
                  connection.open
                  reader := command.execute_reader
                  
                  -- Iterate through result-set
                  from
                     ok := reader.read
                  until
                     not ok
                  loop
                     data_string.append(reader.item ("BookNum").to_string + " <u>" + reader.item ("Title").to_string + "</u> " + reader.item ("Author").to_string + "<br>")
                     ok := reader.read
                  end
                  ltlData.set_text (data_string)
   
                  -- Close everything
                  reader.close
                  connection.close
               end
            end
</script>
</head>
<body bgcolor="#FFFFFF">
<h1 style="font-family:Arial;">Eiffel - SQL Server Database Connection</h1>
<hr>
<font face="Arial">
<form runat=server>
   <asp:literal id="ltlData" runat="server" />
</form>
</font>
</body>
</html>
<!--
--+--------------------------------------------------------------------
--| Eiffel for ASP.NET 5.6
--| Copyright (c) 2005-2006 Robert S. Robbins
--|
--| Robert S. Robbins
--| http://www.williamsportwebdeveloper.com/
--+--------------------------------------------------------------------
-->

 

2 Comments

Comments have been disabled for this content.