Ticket T857194
Visible to All Users

PostgreSql connectionstring

created 5 years ago

When I try to connect to Postgres 12.0 I get the following error

Unable to open database. Connection string: 'Server=127.0.0.1;User ID=postgres;Database=MyDatabase;'; Error: 'Npgsql.NpgsqlException (0x80004005): No password has been provided but the backend requires one (in MD5)

the connectionstring in App.config is the following

<add name="ConnectionString" connectionString="XpoProvider=Postgres;Server=127.0.0.1;User ID=postgres;Password=XXX663;Database=MyDatabase;Encoding=UNICODE" />

was able to create the database MyDataBase using DBUPDATER tool using the same connectionstring.

Found the following on the internet:

This is because of the Persist Security Info feature, which has been implemented in 3.1. Once a connection is open, getting its connection string will return it without a password. This is a security feature that allows you to pass around (open) NpgsqlConnection instances without having to worry about someone extracting the password from it.

The easiest way to work around this is simply to set Persist Security Info to true, which will make things work like in 3.0. Otherwise you need some external way to get the password, i.e. not from the connection.

I added Persist Security Info=true in connectionstring but it does not help

any idea??

thanks

Answers

created 5 years ago

Hello Paolo,

By default, XAF obtains a connection string directly from the configuration file:

C#
winApplication.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

This connection string is then used in the CreateDefaultObjectSpaceProvider method:

C#
protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) { args.ObjectSpaceProviders.Add(new XPObjectSpaceProvider(XPObjectSpaceProvider.GetDataStoreProvider(args.ConnectionString, args.Connection, true), false)); args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null)); }

The application does not open database connections before this. A password can be removed if a connection string is obtained from the NpgsqlConnection.ConnectionString or XafApplication.ConnectionString property somewhere in your code. Please check this. If this does not help, check the exception's callstack and add a breakpoint to the NpgsqlConnection.Open method to see when a connection is opened in your application.

    Comments (2)

      Thank you, you were right, it works now!

      Anatol (DevExpress) 5 years ago

        You are welcome!

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.