context.CreateDatabase fails when using UserId that is not postgres

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
tom.puckett
Posts: 9
Joined: Thu 17 Mar 2016 14:26

context.CreateDatabase fails when using UserId that is not postgres

Post by tom.puckett » Thu 17 Mar 2016 15:11

I have a model developed with Entity Developer 5.8.791 that has been converted into context and entity classes in c#. Using the context.CreateDatabase method, I can deploy this model to a PostgreSQL 9.5 server from c# code if the connection string has a userid of "postgres". I also have another user named "otheruser" on the server that has CREATEDB (and superuser) privilege. If I use this login role with the context.CreateDatabase method, I get an error like this:

PostgreSql.PqSqlException: {"database \"otheruser\" does not exist"}

It seems that the context CreateDatabase method depends somehow on the existence of a database that has the same name as the login role of the connection, seems like a bug.

Just for a test, I created a database named otheruser on my server, and then the context.CreateDatabase method was successful! But I don't want this database and it should not be required, of course. I think some developers don't see this issue because they often use the postgres login role, and a "postgres" database exists on most servers because it is created during the PostgreSQL server software installation.

I also saw this same issue described without a final conclusion here:
http://forums.devart.com/viewtopic.php? ... 7&p=109572

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: context.CreateDatabase fails when using UserId that is not postgres

Post by Shalex » Tue 22 Mar 2016 12:36

Please use

Code: Select all

context.CreateDatabase(false, true);
instead of

Code: Select all

context.CreateDatabase();
Does this work? If not, specify the current text of the error.

tom.puckett
Posts: 9
Joined: Thu 17 Mar 2016 14:26

Re: context.CreateDatabase fails when using UserId that is not postgres

Post by tom.puckett » Mon 04 Apr 2016 13:27

I tried the arguments as suggested but got exactly the same error. This happened no matter whether the target database exists or not. I copied the stack trace below in case that helps.

at Devart.Data.PostgreSql.u.v()
at Devart.Data.PostgreSql.u..ctor(j A_0)
at Devart.Data.PostgreSql.i.a(DbConnectionOptions A_0, Object A_1, DbConnectionBase A_2)
at Devart.Common.ab.a(DbConnectionPool A_0, DbConnectionOptions A_1, DbConnectionBase A_2)
at Devart.Common.DbConnectionPool.a(DbConnectionBase A_0)
at Devart.Common.DbConnectionPool.GetObject(DbConnectionBase owningConnection)
at Devart.Common.ab.c(DbConnectionBase A_0)
at Devart.Common.DbConnectionClosed.Open(DbConnectionBase outerConnection)
at Devart.Common.DbConnectionBase.Open()
at Devart.Data.PostgreSql.PgSqlConnection.Open()
at Devart.Data.PostgreSql.Linq.Provider.PgSqlDataProvider.CreateSchema(Boolean ignoreErrors)
at Devart.Data.Linq.DataProvider.CreateDatabase(Boolean ignoreErrors, Boolean createSchema)
at Devart.Data.Linq.DataProvider.b(Boolean A_0, Boolean A_1)
at Devart.Data.Linq.DataContext.CreateDatabase(Boolean ignoreErrors, Boolean createSchema)
at CdrDbLibTestGui.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Tom.Puckett\Source\Repos\PRMDevelopment\Databases\CdrDbLib\CdrDbLibTestGui\Form1.cs:line 74
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at CdrDbLibTestGui.Program.Main() in C:\Users\Tom.Puckett\Source\Repos\PRMDevelopment\Databases\CdrDbLib\CdrDbLibTestGui\Program.cs:line 19
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: context.CreateDatabase fails when using UserId that is not postgres

Post by Shalex » Mon 04 Apr 2016 14:33

Please send us a small test project so that we can reproduce the issue in our environment.

Post Reply