本文整理汇总了C#中OracleConnection.GetSessionInfo方法的典型用法代码示例。如果您正苦于以下问题:C# OracleConnection.GetSessionInfo方法的具体用法?C# OracleConnection.GetSessionInfo怎么用?C# OracleConnection.GetSessionInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OracleConnection
的用法示例。
在下文中一共展示了OracleConnection.GetSessionInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
if (args.Length != 3)
{
Console.WriteLine("Usage: program.exe <username> <password> <db>");
Environment.Exit(1);
}
string username = args[0];
string password = args[1];
string database = args[2];
OracleConnectionStringBuilder conStr = new OracleConnectionStringBuilder()
{
UserID = username,
Password = password,
DataSource = database
};
using (var con = new OracleConnection(conStr.ToString()))
{
con.Open();
var si = con.GetSessionInfo();
si.Language = "POLISH";
con.SetSessionInfo(si);
try
{
bool exists = UserExists(ProblematicUsername, con);
Console.WriteLine("User exists? = {0}", exists);
if (!exists)
{
CreateUser(ProblematicUsername, ProblematicUserPass, con);
}
GrantConnect(ProblematicUsername, con);
PrintDebug(con);
}
finally
{
con.Close();
}
}
if (TryConnect(ProblematicUsername, ProblematicUserPass, database))
{
Console.WriteLine("OK, connected!");
}
using (var con = new OracleConnection(conStr.ToString()))
{
con.Open();
var si = con.GetSessionInfo();
si.Language = "POLISH";
con.SetSessionInfo(si);
DropUser(ProblematicUsername, con);
}
/*Console.WriteLine("Press enter...");
Console.ReadLine();*/
}
示例2: TryConnect
private static bool TryConnect(string username, string password, string database)
{
OracleConnectionStringBuilder conStr = new OracleConnectionStringBuilder()
{
UserID = username,
Password = password,
DataSource = database
};
using (var con = new OracleConnection(conStr.ToString()))
{
try
{
con.Open();
}
catch (OracleException e)
{
Console.WriteLine("{0} was caught\n HResult={1}\n Source={2}\n ErrorCode={3}\n DataSource={4}\n Number={5}\n Procedure={6}\n StackTrace={7}\n InnerException: {8}",
e.GetType(),
e.HResult,
e.Source ?? "",
e.ErrorCode,
e.DataSource ?? "",
e.Number,
e.Procedure ?? "",
e.StackTrace,
e.InnerException
);
return false;
}
var si = con.GetSessionInfo();
si.Language = "POLISH";
con.SetSessionInfo(si);
try
{
return true;
}
finally
{
con.Close();
}
}
}