0

My C# app connects to Oracle using following connection string format:

Data Source=tnsEntry;User Id=myUsername;Password=myPassword;

Now if there's a user id that starts with space like ' abc' (excluding quotes), how can I specify it in the connection string? Putting it in single/double quotes results in error Ora-1017: Invalid username/password.

Using Oracle.DataAccess, Version=2.112.3.0. Connecting to Oracle 11g.

Reproducible at my end in this minimal sample:

using System;
using Oracle.DataAccess.Client;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            var con = new OracleConnection("User Id=\" abc\";Password=system05;Data Source=REFUPG141");
            try
            {
                con.Open();
                Console.WriteLine("connected.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}
Karan
  • 73
  • 2
  • 11
  • i don't think it s possible to create a user with leading/trailing white space so why not just trim them ? – haki Nov 20 '13 at 12:17
  • @haki it is possible. – Karan Nov 20 '13 at 12:26
  • Can't you use `@` before the connection String in the C# code? Look at the solution here also: http://stackoverflow.com/questions/3824351/how-to-include-ampersand-in-connection-string-password-when-using-entity-framewo – zulqarnain Nov 20 '13 at 12:29

1 Answers1

0

Surrounding the username with double-quotes worked for me:

Note that you need to use double-quotes when creating your user:

SQL> create user "  DUMMY" identified by "pass";

User created.

SQL> grant connect, create session to "  DUMMY";

Grant succeeded.

SQL> conn "  DUMMY"/"pass";
Connected.

Then in .NET I've used this connection string and worked fine:

Data Source=localhost/mySid;User Id="  DUMMY";Password=pass

[EDIT] Important information:

I'm using the Managed .NET Oracle Provider

J.Hudler
  • 1,238
  • 9
  • 26
  • I tried this today with Managed .NET Oracle Provider that you mentioned. Still didn't work to my surprise. Could this be specific to my particular Oracles server instance? – Karan Nov 21 '13 at 15:37
  • That's odd. Yes, could be your Oracle version maybe. Here I'm running Oracle 11g. – J.Hudler Nov 21 '13 at 17:08
  • @Karan: Also, could you please post the code (connection part) you are running this issue? – J.Hudler Nov 21 '13 at 17:09
  • Oracle 11g here too. Also, I added the code in original post now. – Karan Nov 22 '13 at 06:54