Sybase ASE 15with ASP.NET 2.0By Anil MahadevAnil Mahadev provides the ISUG                 ybase continues to make signifi...
SYBASE ASE 15         WITH    A S P. N E T   2.0Steps to building the application                             You can down...
SYBASE ASE 15           WITH    A S P. N E T   2.0    Under Data Sources➠Data Source Configuration Wizardchoose create a n...
SYBASE ASE 15          WITH     A S P. N E T   2.0                                                                  Proble...
Upcoming SlideShare
Loading in...5

Sybase and ASP.NET2.0 Article


Published on

A basic article on using Sybase with ASP.NET

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Sybase and ASP.NET2.0 Article

  1. 1. Sybase ASE 15with ASP.NET 2.0By Anil MahadevAnil Mahadev provides the ISUG ybase continues to make significant Software requirementsTechnical Journal with a‘QuickStart’ tutorial on web S enhancements to its flagship enter- prise class database Adaptive Server Enterprise (ASE). The release of version 1) Windows 2000 and above. 2) A personal copy of SYBASE ASE 15 (Any edition will do, as we are devel-application development with 15 in 2005 along with its subsequent sib- oping for test purposes only, I will beSybase ASE 15 and ASP.NET 2.0 lings, 15.0.1 and 15.0.2, in later years has using the Developer Edition of awoken the curiosity of more and more SYBASE ASE 15 for Windows.) developers who are now taking ASE for a You can download SYBASE ASE 15 spin. Couple this with Sybases commit- from the Sybase website and try it out. ment to supporting additional develop- It’s FREE for development purposes ment platforms, like .NET and J2EE in only (not to be deployed in a produc- addition to Power Builder - and you can tion environment) as specified by the see why this is an exciting time for us license agreement. developers. ase_1500devel 3) Microsoft Visual Studio.NET 2005 What has changed? (Professional or Team System) - you Sybase ASE and .NET have now become can order a free Trial DVD from so much easier to use than the previous Microsoft. releases – and Visual Studio 2005 promises 4) Install the SYBASE ASE 15 Data a whole lot of features that Sybase has Provider for ADO.NET during the taken advantage of in its Data Window installation of SYBASE ASE 15. .NET software. In this piece, We shall be using the pubs2 sample I am happy to share with you my database and authors table. For those experience of using SYBASE ASE 15 of you who do not have the pubs2 with ASP.NET 2.0 within the Visual database installed. Follow these steps Studio 2005 IDE – and I’m going to do to install them on your ASE Server. so without writing a single line of code. a) Open Interactive SQL and from In VS 2005 and ASP.NET 2.0, using the File Menu choose Run Script. ASE 15 has never been as good as it is b) Navigate to your Sybase ASE now. In this first segment, I will take you installation folder and drill down through building a data-driven website to the scripts folder. using Sybase ASE 15’s ADO.NET Data c) Under that, filter by all files and Provider with ASP.NET 2.0. The goal of choose pubs2. the application is that it must display the d) Now the database starts gettingAnil Mahadev is an experienced data- authors from the authors table, it must created for you – and you can viewbase consultant and writer on database also perform sorting and pagination. it from within Sybase Central.technologies with several years training We are going to be using the Grid Now that we have our database and tables& consulting experience. He is View Control for this – so here are the ready, we can visually build applications inavailable at requirements for this tutorial. Visual Studio 2005.30 ISUG TECHNICAL JOURNAL
  2. 2. SYBASE ASE 15 WITH A S P. N E T 2.0Steps to building the application You can download SYBASE ASE 15 from theLaunch Visual Studio 2005. Click on File ➠ New Website.Now you can choose the language and select from C# or VB Sybase website and try it out. It’s FREE foras shown in figure 1. development purposes only and not to be deployed in a production environment as specified by the license agreement. DESIGN & DEVELOPMENTFigure 1We now will be in the source view by default – so switch tothe Design View. Then you can add the following controls onto the pageand set their properties as indicated in the table below.Control Name PropertiesLabel Control Building ASP.NET Apps with Figure 2 Sybase ASE 15GridView Control None needed - only Our application should now look like figure 3. configuration required.We now have our controls in place so we need to perform onemore step before proceeding. We need to add a reference tothe ASE Data Provider Namespace Assembly.a) Right click on the Project and choose Add reference. Now under the tabs, choose under the .NET tab you can see the Sybase.Data.AseClient or alternatively you can navigate to the Sybase ASE Installation folder x:SYBASEASE15DataAccessADONETdll where x is your drive in your own hard drive. Figure 3Next choose the Sybase.Data.AseClient.dll. Then click onOK and your project now hosts the ASE for .NET Assembly Configuring our Data Sourceas shown below. The Sybase ASE .NET Client is registered as We are now going to create a new connection to the ASEa Native Assembly within the Windows operating system. Server. Click on your Grid View Control and under Data This is shown in figure 2. Source choose New Data Source. M AY- J U N E 2 0 0 8 31
  3. 3. SYBASE ASE 15 WITH A S P. N E T 2.0 Under Data Sources➠Data Source Configuration Wizardchoose create a new Connection. Now we will need to build anew Sybase Data Source. Under the System DSN Tab, clicknew and choose Adaptive Server Enterprise as the chosendatabase server. Now you will be taken to a dialog where youwill need to specify an existing connection to a Sybase ASE15 database. The connection dialog will be as shown in the figure 4. Figure 6 Configuring the grid view You will need to choose the connection you have created to connect to Sybase ASE 15. Click next and give this ConnectionString a name, say, pubs2 - and then you have the option to re-use this connection string for multiple pages. Click ‘next’ as shown in figure 7.Figure 4Next you will need to test the connection. Once you get a Figure 7message that says Login Succeeded, it means that the connec-tion to your server is now ready. You will be asked to select a table from Sybase ASE 15. Since [Note: As a security measure ASE does not allow the user to only the views are displayed, choose the ‘Specify a customenter the password directly. Instead the user is given an option to SQL statement’ option and manually enter the SQLenter the password in the next dialog once the user clicks on Test Statement by clicking next as shown in figure 8.Connection.] You will now get a message (as shown in figure 5) forsuccessful connection.Figure 5Reasons for connections not succeeding1) Check your Server status ➠ Running.2) Check the port numbers on your machines.3) Verify the credentials. The Data Source name will be the connection parameter Figure 8that the GridView will take when connecting to your SybaseASE Database Server and displaying the contents onto your We will now get a list of all the author details from theWebForm. authors table. The query that we will be using is a simple The final screen that appears is shown in figure 6. select statement. Select * from authors.32 ISUG TECHNICAL JOURNAL
  4. 4. SYBASE ASE 15 WITH A S P. N E T 2.0 Problem: After configuring your data source, your password does not get saved in the web.config file. Resolution: Add the password as given below in your web.config file under the connection string setting. <connectionStrings> <add name="ConnectionString" connectionString="DSN=SybaseASE15;UID=your ase username;PWD=your ase password" providerName="System.Data.Odbc"/> </connectionStrings>Figure 9 After making the appropriate changes, we now have our Grid DESIGN & DEVELOPMENT View configured and we are ready to run the application. Our final application will appear as shown in figure 13.Figure 10At this point you have the option to customize your query byclicking on the Query Builder button. We are not going to bedoing anything with our query so let’s move along. Click nextand in the last section let’s make sure that we get the desired Figure 13results – so click on the Test Query button. This is shown infigure 10. You should be able to view the final application as shown Click Finish to complete the configuration. in the browser with page 1 and page 3 screens below. There can be times when a table consists of a thousand or To demonstrate the sorting functionality click on themore rows; it’s not advisable to load all the rows onto one au_fname link and see how all author’s first names arepage, so therefore Pagination needs to be enabled for our Grid alphabetized. This is shown in the figure 14.View control. To enable Pagination, Sorting and Selectionclick on the three checkboxes as shown in figure 11. Our Grid View is now ready. You may want to auto-formatyour Grid View and Details View for clearer presentation. Now press F5 to run the application.Figure 11 Figure 14You’ll now see a figure like the one shown below in figure 12. Wow, now wasn’t that easy to work with Sybase ASE 15 using ASP.NET? There are more incredible things you can do; I’ll let you know about more options in forthcoming features and tutorials. Sybase is a great database platform - and you can leverage your existing skills from SQL Server to Sybase by following what is a very efficient learning curve. ■Figure 12 M AY- J U N E 2 0 0 8 33