iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

attach sql db file show me error

i have a sql server connection dialog that user type it's connection string data
and i use folowing article to attach db file that is in application folder:
https://www.advancedinstaller.com/user- ... cript.html
but when the installer install application following error occurred:
[SQLDriverConnect]{SQL_STATE:42000}[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "dbname" requested by login.the login failed
.in sql server connection dialog test connection is successful
whats wrong with that?

thanks in advanced
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,

Do you have the required rights in order to access that database (in this case, "dbname")?

Can you please try to run the setup as administrator and see if that helps? In order to require administrator privileges for a setup, you can go to "Install Parameters" page and check the "Run as Administrator" option. Or, if you have an EXE package type, you can simply right click on it and select "Run as Administrator".

Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

hi,
Run as administrator did not work
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,

Can you please try to manually run the same script from under the same SQL login as from your installer (the same username) and see if that works? Please keep in mind that if the script does not work outside of Advanced Installer (when you run it manually), it can not work from within Advanced Installer either.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

hi
i have same issue and used following article to attach db:
https://www.advancedinstaller.com/user- ... cript.html
but i face the error:
SQLDriverConnect]{SQL_STATE:42000}[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "dbname" requested by login.the login failed
i have sql connection test successful and run as admin but none of them solve the problem.
the script works in management studio but fails during installing the application
any help could be appreciated.
thanks in advanced
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

could you please give me an example aip file that attach db?
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,
SQLDriverConnect]{SQL_STATE:42000}[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database "dbname" requested by login.the login failed
Could you please double check the above error and let me know if it also mentions the user that it fails for (e.g. "Login failed for user 'your_user'")?

If you could find the user, could you please check if there is a login user (for your user) in SQLServer? To do so, you can open SQL Server Management Studio --> "Security" --> "Logins" --> check for your user here.

If the user is not there, could you please add your user and let me know if it helps?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

hi
thanks for reply
i send you my setup log for more details.
i use sa user and it's password that when i click test sql connection the result is successful in setup. but when wanna execute the attach script the above error occur.
i thinks i missed something.please check and any solution appreciated
Attachments
setup log.LOG
(264.1 KiB) Downloaded 236 times
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,

Unfortunately, the log file does not give many details as to why this is failing.

In order for me to further investigate this, could you please forward me a copy of your .AIP file by e-mail at support at advancedinstaller dot com?

Also, could you please follow the steps I've given in my previous thread and let me know if that helps in any way?

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

hi
could you please follow the steps I've given in my previous thread and let me know if that helps in any way?
i use sa user that exist in Security -> Logins in SSMS and can attach my db with script with SSMS without any problem.
could you please forward me a copy of your .AIP file by e-mail at support at advancedinstaller dot com?
i attached my aip file please check it.
Attachments
Sample Setup.aip
(38.53 KiB) Downloaded 252 times
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,

Thank you for the sent .AIP file.

I have further investigated this and I have also tried to reproduce this behavior on my machine, but unfortunately to no avail - everything worked as expected for me.

One thing I have noticed from the log file you've earlier sent:

- the DATABASE_PROP is nowhere to be found in your log file. Are you connecting to any database during the "SQLServerConnectionDlg" dialog? If not, please connect to one by clicking the "..." button and then selecting a database. If no databases are found, then insert a name into the "Database" field - the name should be different from the database you are trying to attach.

Hope this helps somehow.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

Hi
Thanks for reply.
One thing I have noticed from the log file you've earlier sent:

- the DATABASE_PROP is nowhere to be found in your log file. Are you connecting to any database during the "SQLServerConnectionDlg" dialog? If not, please connect to one by clicking the "..." button and then selecting a database. If no databases are found, then insert a name into the "Database" field - the name should be different from the database you are trying to attach.
i thinks do not need to connect to a database because i wanna attach database during installation.

Code: Select all

CREATE DATABASE TestDb ON
  ( FILENAME = N'$Install_Path$TestDb.mdf' ),
  ( FILENAME = N'$Install_Path$TestDb_log.ldf' )
FOR ATTACH ;
and of course i put database name in Predefined section in database server of AI

and one more thing is that i disable DatabaseCombo in SQLServerConnectionDlg because i think i do not need to set it.
is all i noted is wrong and the Database_Prop must be set?
please give a solution. i attach image from my predefined connection
thanks
Attachments
Predefined connection
Predefined connection
Capture.PNG (10.67 KiB) Viewed 16762 times
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,

I've had another look over the sent log file and I could notice that you are trying to connect to the SQL Server instance using an SQL login with the following user:

Code: Select all

sa
Could you please try to manually connect to the same instance using the "sa" account, try to run your script from there and see if that works?

Additionally, could you please go to "SQL Databases" page --> select your predefined connection --> uncheck the "Impersonate User" option from the toolbar (from what I can see, it is checked in your project file).

If that is of no help, please forward me a download link for the setup built with the .AIP file you previously provided.

Looking forward to hearing from you.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
iranlondon
Posts: 21
Joined: Wed Mar 13, 2019 3:13 pm

Re: attach sql db file show me error

hi
Could you please try to manually connect to the same instance using the "sa" account, try to run your script from there and see if that works?
the script is work with "sa" account in sql management studio without any problem.
Additionally, could you please go to "SQL Databases" page --> select your predefined connection --> uncheck the "Impersonate User" option from the toolbar (from what I can see, it is checked in your project file).
i unchecked "Impersonate User" option and compile the setup but the setup did not work and the error do not go away.

i attached the aip setup file.
the download link for exe setup is: http://uploadboy.me/bqy9gixkwkcx/Sample Setup 1.0.0.zip.html

thanks in advanced
Attachments
Sample Setup.aip
(38.48 KiB) Downloaded 243 times
Catalin
Posts: 6586
Joined: Wed Jun 13, 2018 7:49 am

Re: attach sql db file show me error

Hello,

First of all, please accept my apologies for the delayed reply, but we were quite busy lately.

Thank you for the provided files.

I was indeed able to replicate the behavior.

Here is what needs to be done:

1. go to "SQL Databases" page --> "DlgPredefinedConnection" --> in the "Database" field, change the database name from "TestDb" to another name (this is required because your script already creates a database with that name)

2. check the "Create database if it does not exist" option

3. now please go to "Files and Folders" page --> double click on the "TestDb.mdf" file --> "Permissions" tab --> "New..." --> set "Full Control" permissions for the [GRP_USERS]

4. repeat step 3 for the "TestDb_log.ldf" file as well

5. rebuild the project & retest the scenario

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”