RSSAll Entries Tagged With: "database"

Opening a connection to access database in c#

To create a connection between a database and the web application, the Open() method of the Connection class is called. It is used to open a connection to a data source with the property settings specified by the connection string.

string strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=C:\\database\\Access\\w3mentor.accdb;";
accConnection = new OleDbConnection(strConnectionString);
try
{
accConnection.Open();
}
catch (OleDbException e)
{
[...]

Retrieving a database insert Index ID using DBI

#!/usr/bin/perl
 
use DBI;
use strict;
 
my $username = "dbuser";
my $password = "dbpassword";
my $dsn = "dbi:mysql:goo:192.168.1.10";
my $dbh = DBI->connect($dsn,$username,$password)
or die "Cannot connect to database: $DBI::errstr";
my $sth = $dbh->prepare("INSERT INTO urls VALUES
(”,’http://www.w3mentor.com/’,'tutorials’,unix_timestamp(),’query words’)");
$sth->execute() or die "Cannot execute sth: $DBI::errstr";
my $insertid = $dbh->{’mysql_insertid’};
print "$insertid\n";
$dbh->disconnect();

List Valid DSNs for databases using DBI

#!/usr/bin/perl
use strict;
use DBI;
my @drivers;
@drivers = DBI->available_drivers;
foreach my $driver (@drivers) {
print "$driver driver is available\n";
my @dsns = DBI->data_sources($driver);
foreach my $dsn (@dsns) {
print "\tDSN: $dsn\n";
}
}

List currently installed database drivers using DBI

#!/usr/bin/perl
use strict;
use DBI;
my @drivers;
@drivers = DBI->available_drivers();
foreach my $dbd (@drivers) {
print "$dbd driver is available\n";
}
exit;

Store State in a SQL Server Database in ASP.NET

We can store session information in a SQL Server database. Add the following configuration to the web.config:

<sessionState
mode="SQLServer"
sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false"
timeout="20" />

The .NET Framework comes with a SQL script (InstallSqlState.sql, located in the same directory as machine.config) to perform initialization of the database on your SQL Server instance, to store session information.

.NET Framework Data Provider Implementations

.NET Framework Data Provider for ODBC
Provides connectivity to any data source that implements an ODBC interface; this includes Microsoft SQL Server, Oracle, and Microsoft Access databases. Data provider classes are contained in the System.Data.Odbc namespace and have the prefix Odbc.
.NET Framework Data Provider for OLE DB
Provides connectivity to any data source that implements an [...]

MySQL server security measures

Operating system security process can be improved with the following recommendations:

Install software as ‘root’ OS user. The file permissions of all MySQL binary and support files are to be owned by ‘root’.
Restrict access to the ‘root’ OS user via sudo privileges. Be diligent by only granting access in limited form.
Configure an OS ‘mysql’ user, but [...]

MySQL Security Precautions

Developers/Administrators can improve security for MySQL client access with the following recommendations:

Always set a MySQL ‘root’ user password.
Change the MySQL ‘root’ user id to a different name, e.g. ‘dba’.
Only enable SUPER privileges to dba accounts, and only ever for ‘localhost’.
Application user permissions should be as restrictive as possible.
Never use ‘%’ for a hostname.
Never use ALL [...]

Store email and username in mysql database using php

<?php
//opens connnection to mysql server
 
$dbc = mysql_connect(’localhost’,'root’,”);
if (!dbc){
die(’Not Connected:’ . mysql_error());
}
//select a database
 
$db_selected = mysql_select_db("rivals",$dbc);
if(!$db_selected)
{
die("can’t connect :" . mysql_error());
}
 
$query = "UPDATE `database` SET email=’something’ WHERE username=’rivals’";
$result = mysql_query($query, $dbc) or die(mysql_error());
 
$username = $_GET[’username’];
$email = $_GET[’email’];
$password = $_GET[’password’];
$insert = "INSERT INTO `database` (`username`, [...]

Using MySQLi Object Interface with PHP to insert data

The following is an example of using MySQLi Object Interface with PHP to insert data into a database table.

$mydb = new mysqli(’localhost’, ‘username’, ‘password’, ‘databasename’);
$sql = "INSERT INTO users (fname, lname, comments)
VALUES (‘$_POST[fname]‘, ‘$_POST[lname]‘, ‘$_POST[comments]‘)";
if ($mydb->query($sql) == TRUE) {
echo "user entry saved successfully.";
} else {
echo "INSERT attempt failed" ;
}
$mydb->close();