/usr/share/asp.net-demos/1.1/webcontrols/dbpage1.aspx is in asp.net-examples 4.2-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | <%@ Page language="C#" %>
<%@ Register TagPrefix="mono" TagName="MonoSamplesHeader" src="~/controls/MonoSamplesHeader.ascx" %>
<%@ import namespace="System.Configuration" %>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Reflection" %>
<%@ import namespace="System.IO" %>
<html>
<script runat=server>
static Type cncType = null;
void GetConnectionData (out string providerAssembly, out string cncTypeName, out string cncString)
{
providerAssembly = null;
cncTypeName = null;
cncString = null;
NameValueCollection config = ConfigurationSettings.AppSettings as NameValueCollection;
if (config != null) {
foreach (string s in config.Keys) {
if (0 == String.Compare ("DBProviderAssembly", s, true)) {
providerAssembly = config [s];
} else if (0 == String.Compare ("DBConnectionType", s, true)) {
cncTypeName = config [s];
} else if (0 == String.Compare ("DBConnectionString", s, true)) {
cncString = config [s];
}
}
}
Version ver = Environment.Version;
if (providerAssembly == null || providerAssembly == "")
if (ver.Major == 2)
providerAssembly = "Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
else if (ver.Major == 4)
providerAssembly = "Mono.Data.Sqlite, Version=4.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756";
else
throw new InvalidOperationException (String.Format ("Framework version {0} is not supported by this demo.", ver));
if (cncTypeName == null || cncTypeName == "")
cncTypeName = "Mono.Data.Sqlite.SqliteConnection";
if (cncString == null || cncString == "") {
string dbPath = Path.Combine (Path.GetDirectoryName (Request.MapPath (Request.FilePath)), "dbpage1.sqlite");
cncString = String.Format ("URI=file:{0},Version=3", dbPath);
}
}
void ShowError (Exception exc)
{
noDBLine.InnerHtml += "<p><b>The error was:</b>\n<pre> " + exc + "</pre><p>";
theForm.Visible = false;
noDBLine.Visible = true;
}
IDbConnection cnc;
void Page_Init (object sender, EventArgs e)
{
string connectionTypeName;
string providerAssemblyName;
string cncString;
GetConnectionData (out providerAssemblyName, out connectionTypeName, out cncString);
if (cncType == null) {
Assembly dbAssembly = Assembly.LoadWithPartialName (providerAssemblyName);
if (dbAssembly == null)
throw new ApplicationException (String.Format ("Data provider assembly '{0}' not found",
providerAssemblyName));
cncType = dbAssembly.GetType (connectionTypeName, true);
if (!typeof (IDbConnection).IsAssignableFrom (cncType))
throw new ApplicationException ("The type '" + cncType +
"' does not implement IDbConnection.\n" +
"Check 'DbConnectionType' in server.exe.config.");
}
cnc = (IDbConnection) Activator.CreateInstance (cncType);
cnc.ConnectionString = cncString;
try {
cnc.Open ();
} catch (Exception exc) {
ShowError (exc);
}
}
void Page_Unload ()
{
if (cnc != null) {
try {
cnc.Close ();
} catch {}
cnc = null;
}
}
void Page_Load (object sender, EventArgs e)
{
if (!IsPostBack){
PersonFilter.Text = "%";
MailFilter.Text = "%";
UpdateTable (PersonFilter.Text, MailFilter.Text);
}
}
void Filter_Changed (object sender, EventArgs e)
{
UpdateTable (PersonFilter.Text, MailFilter.Text);
}
void UpdateTable (string filterPerson, string filterMail)
{
if (cnc == null)
return;
IDbCommand selectCommand = cnc.CreateCommand();
IDataReader reader;
string selectCmd = "SELECT * FROM test " +
"WHERE person like '" + filterPerson + "' AND " +
"email like '" + filterMail + "'";
selectCommand.CommandText = selectCmd;
int rowCount = 0;
try {
reader = selectCommand.ExecuteReader ();
while (reader.Read ()) {
TableRow row = new TableRow ();
for (int i = 0; i < reader.FieldCount; i++) {
TableCell cell = new TableCell ();
cell.Controls.Add (new LiteralControl (reader.GetValue (i).ToString ()));
row.Cells.Add (cell);
}
myTable.Rows.Add (row);
rowCount++;
}
if (rowCount == 0) {
TableRow row = new TableRow ();
TableCell cell = new TableCell ();
cell.Controls.Add (new LiteralControl ("No results returned from query."));
row.Cells.Add (cell);
myTable.Rows.Add (row);
}
} catch (Exception exc) {
ShowError (exc);
}
}
</script>
<head>
<link rel="stylesheet" type="text/css" href="/mono-xsp.css">
<title>Some DB testing</title>
</head>
<body><mono:MonoSamplesHeader runat="server"/>
<span runat="server" visible="false" id="noDBLine">
<h3>Database Error</h3>
Sorry, a database error has occurred.
<p>
You should set up a database of your choice and then modify the variables DBProviderAssembly, DBConnectionType and
DBConnectionString in <tt>xsp.exe.config</tt> (or <tt>mod-mono-server.exe.config</tt> if running the tests under Apache/mod_mono)
file to fit your needs.
<p>
The database should have a table called customers created with the following command (or similar):
<pre>
CREATE TABLE "test" (
"person" character varying(256) NOT NULL,
"email" character varying(256) NOT NULL
);
</pre>
</span>
<form id="theForm" runat="server">
Choose the SQL filters and click 'Submit'.
<p>
<asp:Label runat="server" Text="Person Filter: "/>
<asp:TextBox id="PersonFilter" Text="" TextMode="singleLine" runat="server" maxlength="40" />
<p>
<asp:Label runat="server" Text="Mail Filter: " />
<asp:TextBox id="MailFilter" Text="" TextMode="singleLine" runat="server" maxlength="40" />
<p>
<asp:Button id="btn" runat="server" Text="Submit" OnClick="Filter_Changed" />
<p>
<asp:Table id="myTable" HorizontalAlign="Left" Font-Size="12pt" GridLines="both"
CellPadding="5" runat="server"/>
</form>
</body>
</html>
|