Patch to use mssql with something other then [dbo].

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/21/2007 2:20:21 PM
Gravatar
Total Posts 16
www.CodeWise.nl

Patch to use mssql with something other then [dbo].

Dear Joe,

Sorry about the long post, hope you get to the end of it ;-)


I ran into a little problem while setting up mojoportal and made a small change...

My problem:
I ran into a the problem with my isp, the problem happened while setting up
the MSSQL database.
As I'm not the database owner (dbo), so I cannot create tables named
[dbo].mp_Users etc. the "dbo" needed to be replaced with "code@codewise_nl".

My initial solution:
For the initial creation of the database I was unable to use script
1CreateDatabase.sql, but this should be no problem. In 2CreateTables.sql and
3CreateStoredProcedures.sql I needed to remove all "[dbo]." (a quick search
and replace fixed this). Now when firing up mojoportal I had to change the
upgrade scripts, then I noticed the upgrade scripts are not executed
automatically because mojoPortal.Data.MSSQL\dbPortal.cs uses the dbo directly.
After fixing this all seems to be running nicely.

The "patch":
Now I wanted to provide a solution for future versions where I needed this
and ensure there is a workaround for other people with the same problem.
I took the liberty to add a new appsetting to the web.config:
<add key="MSSQLDatabasePrefix" value="dbo" />
(dbo is code@codewise_nl in my case)

Then I modified all the upgrade scripts so that (the missing . is
intentionally so you can remove the dbo. completely if you want to)
[dbo]. got [*MojoDatabasePrefix*]
dbo. got *MojoDatabasePrefix*
e.g.
CREATE PROCEDURE [dbo].[mp_Roles_SelectRolesUserIsNotIn]
changed to
CREATE PROCEDURE [*MojoDatabasePrefix*][mp_Roles_SelectRolesUserIsNotIn]

Then I changed
mojoPortal.Data.MSSQL\dbPortal.cs

I added private static string GetDatabasePrefix(string connectionString)
This function returns the new appsetting (if not present in the web.config
it returns "dbo")

I modified public static bool RunScript(String script, String overrideConnectionString)
this function now uses GetDatabasePrefix() to replace [*MojoDatabasePrefix*]
and *MojoDatabasePrefix* in the script

If you include this patch people with the same problem can install
mojoportal by:
- do a search/replace on 2CreateTables.sql and 3CreateStoredProcedures.sql to
replace [dbo]. with nothing
- setting the new appsetting MSSQLDatabasePrefix in web.config

Impact:
- Upgrade, new upgrade sql files will need to have the [dbo]. and dbo.
replaced by the new notations
- Security, possible sql injection attacks. This is not likely because we get
the injected text from the web.config and RunScript is only used in the upgrade (as far as I can tell)
- Existing users will still get the [dbo]. in the scripts (because that is the default)

I hope you can use the modified version or give me an other workaround.

You can get the modifications (against 2.2.2.8) from test.onshuis.tk/Mojo-dbo-patch-2.2.8.zip

Regards,
Jelle Hissink

6/22/2007 8:12:00 AM
Gravatar
Total Posts 18439

Patch to use mssql with something other then [dbo].

Hi Jelle,

I will look into doing something similar, but I don't want to have to do anything different with the upgrade scripts, I generate those with a tool and do not want to have to remember to modify them with a special tag after generating. It will be easier to just replace "[dbo]." with the value from web.config which will also default to [dbo].

Joe

6/24/2007 2:31:56 PM
Gravatar
Total Posts 16
www.CodeWise.nl

Re: Patch to use mssql with something other then [dbo].

Joe,

in the update scripts you should not only replace [dbo]. but also some of the dbo. referals (although dbo. is also used to reference the system tables wich should not be replaced).

Regards,

Jelle

You must sign in to post in the forums. This thread is closed to new posts.