Using variables within a SQL*Plus connect string - scripting

I have a SQL*Plus routine embedded inside of a KornShell (ksh) script.
As long as I hard code my SID in the connect string, the entire routine works as intended.
However, depending on whether I am in debug mode, or production mode, will depend on which SID I want to connect to.
When I attempt to use a variable in place of the hardcoded SID, inside of the connect string, it continually errors out.
I have tried single quotes, double quotes, braces, back-slashing the $, etc.
But, nothing that I have tried, short of hardcoding the SID in this connect string seems to work.
Here is an example of my connect string:
sqlplus UserID/"Passwd"#(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HostID)(PORT = Port))(CONNECT_DATA = (SID = $ORASID)))
Remember that it works, if I simply hardcode the SID:
sqlplus UserID/"Passwd"#(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = HostID)(PORT = Port))(CONNECT_DATA = (SID = OraSID)))
Can anyone tell me how I can get the SID to work as a fed-in variable?
Thanks in advance.

This works for me:
sqlplus -s $user/$password#$SID
and so does this:
sqlplus -s $myLogin
where $myLogin = user/password#SID

Related

how to close connection after running cuteFTP .vbs script?

we are using the macro record facility available in cuteFTP to generate a vbs file which we use to upload a local copy of the database to Godaddy.
How do we go about closing the connection on upload completion as if we do not there is a risk that the file is locked and causes the website to fall over? Is there a better way to do this?
thanks for any pointers
' Create TEConnection object
Set MySite = CreateObject("CuteFTPPro.TEConnection")
' Initialize remote server host name, protocol, port, etc.
MySite.Host = "ftp.servername.here"
MySite.Protocol = "FTP"
MySite.Port = 21
MySite.Retries = 30
MySite.Delay = 30
MySite.MaxConnections = 4
MySite.TransferType = "AUTO"
MySite.DataChannel = "DEFAULT"
MySite.AutoRename = "OFF"
' WARNING!!! SENSITIVE DATA: user name and password.
MySite.Login = "username"
MySite.Password = "password"
MySite.SocksInfo = ""
MySite.ProxyInfo = ""
' Connect to remote server
MySite.Connect
MySite.UploadAsync "C:\Projects\access_db\propertyDB.mdb", "/access_db/propertyDB.mdb"
A quick look at the Official Documentation suggests you could use the Close() method and pass the "EXITNOPENDING" option as an argument.
From the Official Documentation:
Close
Use the Close method to exit the Transfer Engine. You can include parameters to exit only on certain conditions.
Syntax
Object.Close (BSTR bstrParameter)
Parameters
""(default empty), "CLOSE", "EXIT"—Closes TE (all tasks will be stopped)
"EXITNOPENDING"—Closes TE if no pending tasks available
Example
Set MySite = CreateObject("CuteFTPPro.TEConnection")
MySite.LocalFolder = "c:\temp"
MySite.TransferURLAsync "ftp://ftp.cuteftp.com/pub/cuteftp"
MySite.Close "EXITNOPENDING"

HSQLDB how to have multiple in memory databases

For instance, for each unit test I'd like to have a "different" database to use, but within the same JVM.
Appears that the "first time" you create an HSQL in-memory database, that becomes the "canonical" password:
String DB_CONNECTION_STR = "jdbc:hsqldb:mem:MySpecialTestDb";
String DB_USERNAME_STR = "sa";
String DB_USERNAME_PASSWORD = "";
DriverManager.getConnection(DB_CONNECTION_STR, DB_USERNAME_STR, DB_USERNAME_PASSWORD);
after this point, if you create a new connection to jdbc:hsqldb:mem:MySpecialTestDb it will connect to the same DB (and you'll need that same username and password unless you've run some privilege granting within it). So to create a second DB, just specify a different name, and/or password:
String DB_CONNECTION_STR = "jdbc:hsqldb:mem:AnotherTestDb";
String DB_USERNAME_STR = "sa"; // could use different here, doesn't matter
String DB_USERNAME_PASSWORD = "";
DriverManager.getConnection(DB_CONNECTION_STR, DB_USERNAME_STR, DB_USERNAME_PASSWORD);
and it will effectively create a new in memory database for you.
See also https://stackoverflow.com/a/23544323/32453

PDO - connection - how to protect

$_pdo = new Data('mysql:host='.$db_host.';dbname='.$db_name.';port='.$db_port, $db_user, $db_pass, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES '.$charset));
Variables come from form.
User can make a sql injection if I don't strip this variables?
Connect credentials should not come from user under any circumstances.
You have to store them in your server in some config file. And then use with connect string.
Please note that charset should be set in DSN, not options.
include 'settings.php';
$dsn = "mysql:host=$db_host;dbname=$db_name;port=$db_port;charset=$charset";
$pdo = new Data($dsn, $db_user, $db_pass);
If you are accepting input from a form to create the connection I would probably use some sanitization functions to clean it up before using it. If this is being stored in a text file or a database it would be a good idea to sanitize before it is saved as well before it is used.
http://php.net/manual/en/function.filter-var.php
$db_host = filter_var($db_host,FILTER_SANITIZE_FULL_SPECIAL_CHARS);
Equivalent to calling htmlspecialchars() with ENT_QUOTES set. Encoding
quotes can be disabled by setting FILTER_FLAG_NO_ENCODE_QUOTES. Like
htmlspecialchars(), this filter is aware of the default_charset and if
a sequence of bytes is detected that makes up an invalid character in
the current character set then the entire string is rejected resulting
in a 0-length string.
http://www.php.net/manual/en/filter.filters.sanitize.php

Question about build.properties

I'm writing a program that uses JDBC and connects to a database and does some edits / deletes. I need to put the URL, username, and password fields into a build.properties file, but I'm not sure how this would look or how to really get this to work.
(I'm completely new to this and haven't found any resources related to this specifically)
For example, in my code I have something like this :
String username = "something"
String password = "something"
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:#(DESCRIPTION=(ENABLE=BROKEN)" + "(FAILOVER=ON)(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP) ... etc", username, password);
and I want to put this in build.properties and for my code to create the connection using these properties instead of how I'm doing it now.
Any help would be appreciated!
Something like this:
First, create database.properties:
database.url = jdbc:mysql://host:port/database
database.driver = com.mysql.jdbc.Driver
database.username = username
database.password = password
Second, put the database.properties in your CLASSPATH.
Code looks something like this:
InputStream is = this.getClass().getClassLoader().getResourceAsStream("database.properties");
Properties dbProperties = Properties.load(is);
Class.forName(dbProperties.getProperty("database.driver"));
Connection connection = DriverManager.createConnection(dbProperties.getProperty("database.url"));
I didn't compile it, and I'm not sure if the syntax is 100% correct, but this illustrates the main idea.

How to resolve the domain server name from .NET

Hi
In a single server Windows domain, does anyone know how to get the servername.
For example, in my test environment, we have a single Windows Small Business Server 2008 called horatio, it is the domain controller for longtest.local.
I have played around with the system.dns (with no positive results) :
Dim myIP As IPHostEntry = Dns.GetHostEntry(My.Computer.Name)
Dim IPAddress As String = myIP.AddressList.GetValue(0).ToString
Dim myFullDomainName = Dns.GetHostEntry(IPAddress).HostName
Dim DomainParts() As String = myFullDomainName.Split("."c)
Dim DomainName As String = DomainParts(1)
However, I cannot seem to grab the servername, I need a function like :
GetDomainServer() that will return horatio (from the example above.
Driving me a bit mad this one.
Regards
Mark Harby
Nottingham. UK
There's an environment variable called LOGONSERVER that you can use:
var domainServerName = Environment.GetEnvironmentVariable("LOGONSERVER");
Ask the server. Like environment variable. The local machine name is available in one environment variable.