Using the driver to install Drupal, it creates the tables in the database, but then returns a blank screen, without allowing me the option to finish the install. Going to the root of the site produces the following error:

Additional uncaught exception thrown while handling exception.

Original
PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot find either column "dbo" or the user-defined function or aggregate "dbo.SUBSTRING_INDEX", or the name is ambiguous.: SELECT DISTINCT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias}; Array ( ) in drupal_path_alias_whitelist_rebuild() (line 381 of C:\Inetpub\wwwroot\drupal\includes\path.inc).

Additional
PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. in variable_set() (line 805 of C:\Inetpub\wwwroot\drupal\includes\bootstrap.inc).

I am currently testing on Windows 2003 SP2 with IIS6, PHP 5.3.6 with the latest SQL Server drivers installed from Microsoft. I also have had this happen using II7 running on Windows 7 SP1 Enterprise, with the same PHP, and the x64 drivers from MS.

Comments

designingsean’s picture

Working with my DBA here, this is what we have been able to figure out:

We can fix the first issue by using two-part naming system to call the function (eg drupal.SUBSTRING_INDEX). But is it possible to update this module to allow all of the DDL objects reside in a user schema instead of DBO?

For issue two, on SQL Server 2008 R2 you cannot explicitly convert varchars to varbinary (see http://msdn.microsoft.com/en-us/library/ms187928.aspx). Any thoughts on how to move forward on this error? We still getting it even after clearing the first.

SQL_Monkey-1’s picture

Priority: Normal » Major
damien tournoud’s picture

We hardcode 'dbo' only in one place, so it should be an easy fix. We just need to figure out what is the proper way to get the schema of the current user. Patches welcome!

SQL_Monkey-1’s picture

Can you easily pull the DefSchemaName for the user that Drupal is logging in with?

Eg: EXEC sp_helpuser 'DrupalUser'

...additionally, by default in SQL Server, if left schema is undefined (single-part naming) SQL Server's default behavior is to assume that the user is looking for objects in the default schema -- so, if you simply remove 2-part naming completely this *should* remove this issue entirely.

I have not dug into the code to find where the 'dbo' setting is hard-coded... so, unsure I can provide a patch directly.

Any insight into Issue 2: "Implicit conversion from data type nvarchar to varbinary(max) is not allowed."

damien tournoud’s picture

...additionally, by default in SQL Server, if left schema is undefined (single-part naming) SQL Server's default behavior is to assume that the user is looking for objects in the default schema

That applies to everything, *except* UDF. Which is why we have to add an explicit schema in there.

damien tournoud’s picture

Also I hope there is a better way to get this information then calling a stored procedure.

SQL_Monkey-1’s picture

Yes there is:

select u.default_schema_name
from sys.database_principals u
where u.type <> 'R' AND u.name = 'DrupalUserName'

damien tournoud’s picture

That's even worse :) I'm sure there is something in the metadata of the open connection about the active schema, but not sure if PDO exposes it or not. There should be no need for a query here.

SQL_Monkey-1’s picture

Ahhh.... you want to pull it straight of the PDO properties directly. Unlikely -- I don't see that the driver returns any properties that would get you there... Even if you wanted to kludge of using the PDO::exec (http://msdn.microsoft.com/en-us/library/ff628158.aspx) using the above statement to return it -- you'd be stuck as "PDO::exec does not return results for a SELECT statement."

Doesn't appear that the PDO driver creates any obj that captures any attributes of the login involved in creating the connection (maybe that's a good idea for securities sake).... I looked into the conn.cpp/core_conn.cpp for the PHP SQL Driver - no references to anything that would indicate user-default schema...

...but, that would already be too deep to expect it to be patched in here at the Drupal/SQL level I guess..

So... is the answer: "Use dbo schema and everything will work" fix the "Cannot find either column "dbo" or the user-defined function or aggregate" issue?

Still unsure how to resolve the: "Implicit conversion from data type nvarchar to varbinary(max) is not allowed" problem mentioned in the original post.

damien tournoud’s picture

Seems that the best way would be SCHEMA_NAME(). We could fetch that immediately after login at the cost of another round trip (which is quite significant in some scenarios, for example on Microsoft Azure).

damien tournoud’s picture

Title: Error immediately after install » Properly handle the user-bound schema
Status: Active » Needs review
StatusFileSize
new938 bytes

I think those two errors are likely related. The problem is that we don't properly take into account the default schema, and instead we consider that it is always "dbo".

Here is a patch for review and testing.

damien tournoud’s picture

Status: Needs review » Fixed
StatusFileSize
new1.51 KB

I committed the attached patch and tagged a RC3 version. Please test and report back! Tentatively marking as fixed.

designingsean’s picture

Status: Fixed » Closed (fixed)

Downloaded and installed RC3, ran through the install on a clean DB. No issues, site is working as it should. Thanks!

SQL_Monkey-1’s picture

Thanks for the quick update/patch Damien ! We'll let you know if anything else crops up.

designingsean’s picture

Version: 7.x-1.x-dev » 7.x-1.2
Status: Closed (fixed) » Active

This error has returned as of the 1.2 version of the driver. 1.x-dev also shows this issue. Reverting back to 1.1 clears the problem. The error appears when trying to view any node, though not when editing.

PDOException: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot find either column "Drupal" or the user-defined function or aggregate "Drupal.SUBSTRING", or the name is ambiguous.

artod4789’s picture

Version: 7.x-1.2 » 7.x-1.1

I had the same issues on 1.2, so I reverted back to 1.1 and it seemed to work...until I logged in as the admin and tried to see content and create new content. Now I'm getting the error again. But the moment I log out, I'm fine.

I can see the list of content and a lot of the admin functions, just nothing else. And I see when I tried to create data, I put in text into all fields and published and I can see that the test content was created as it shows up in the find content listing, I just can't actually see it.

damien tournoud’s picture

You should visit the install.php page once so that the driver re-creates the missing user-defined functions.

designingsean’s picture

Version: 7.x-1.1 » 7.x-1.2

Visiting install.php just gave me the "Drupal is already installed" message, but now browsing the site I am no longer receiving the previous error messages via the database.

I am surprised that just visiting the install.php page alone would cause the db driver to check for needed updates and then execute, without any intervention from the user.

I would also suggest including these instructions in an "Upgrade" section in the documentation somewhere in the future.

That being said, my issue appears to be fixed. However, I am going to leave the status alone, since someone else seems to be having a similar problem.

jackfoust’s picture

Visiting install.php worked for me too, which is great because I had been running with comment module disabled to avoid the error.

damien tournoud’s picture

Status: Active » Closed (fixed)