Shared Non-Sitefinity Database Issue
I've been having lots of trouble getting a custom module installed the way I want to get it done. So I broke everything down to the simplest components and I was able to get it installed in this fashion. However, one of my requirements is that the data in the custom module be stored in a database separate from the Sitefinity Instance database. I thought this would be really easy to do so what I did was add a new entry to the data.config of my project.
I've changed the actual names but this should give the idea.
<
add
connectionString
=
"data source=SERVER1;Integrated Security=SSPI;initial catalog=SitefinityInstance"
providerName
=
"System.Data.SqlClient"
dbType
=
"MsSql"
name
=
"Sitefinity"
/>
<
add
connectionString
=
"data source=SERVER1;Integrated Security=SSPI;initial catalog=SharedDatabase"
providerName
=
"System.Data.SqlClient"
dbType
=
"MsSql"
name
=
"SharedDatabase"
/>
public static CustomModuleContext Get()
return OpenAccessConnection.GetContext(new CustomModuleMetaDataProvider(), "SharedDatabase") as CustomModuleContext;
In a couple of my projects I had to add a separate database for my own stuff (non-Sitefinity). It worked fine. Just like you, I have added the second connection string, referenced to it in code and used it with no issues at all.
Now, that I am thinking about it, I probably could have just added the extra table(s) to the Sitefinity database and eliminated the need for two databases. I was a bit unsure about whether the Sitefinity's upgrade procedure would affect my tables in any way. Perhaps someone from Telerik can answer: If I add my own table to the Sitefinity database;
1 - Do you recommend it?
2 - Do you ignore non recognised tables in your upgrade procedure?
If the answer is Yes and Yes, then next time when I need to store some stuff, I will just create a table in the Sitefinity database.
Thanks for the response. I eventually got my module to start working but now I noticed that when it created the database on the backend it created the columns in a very unfriendly matter. For instance, my table is saving contact information but the Sitefinity ORM order the columns so that the ZIP code is first when I would like to have the key first. Is there anyway to order this through code or do I need to fix it manually in the DB?