简体   繁体   中英

piece of code works in console application, but does not works inside nunit test

Simple console application open connection without any problems:

    static void Main(string[] args)
    {
        string connectionString = String.Format(
           @"Provider=OraOLEDB.Oracle;PLSQLRSet=1;Password={0};Persist Security Info=True;User ID={1};Data Source={2};OLEDB.NET=true;FetchSize=5000",
            "pwd", "schema", "server");

        using (IDbConnection con = new OleDbConnection(connectionString))
        {
            con.Open();
            Console.WriteLine("Opened");
        }
        Console.ReadKey();
    }

but if try do same in the nunit test method:

public class UnitTest1
{
    [Test]
    public void TestMethod1()
    {
        string connectionString = String.Format(
           @"Provider=OraOLEDB.Oracle;PLSQLRSet=1;Password={0};Persist Security Info=True;User ID={1};Data Source={2};OLEDB.NET=true;FetchSize=5000",
            "pwd", "schema", "server");

        using (IDbConnection con = new OleDbConnection(connectionString))
        {
            con.Open();
        }
    }
}

I have got exception: ORA-12154: TNS:could not resolve the connect identifier specified

Obviously problem that is in environment.

How to 'configure' nunit for using 'same' settings as console application

some details:

target framework: 4.0 target platform: x86 nunit 2.5.9 OS: Windows 7 x64

Problem cause parenthesis in folder name. (C:\\Program Files (x86))

If I run nunit from folder c:\\something(nunit)\\ I got same error.

Replacing VS path to short 8.3 names does not help me. So had to install Oracle Client 11 and problem is gone.

检查以下是否有帮助: http//ora-12154.ora-code.com/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM