SubSonic 2.2 encrypted connection string - subsonic2.2

I want to use SubSonic on a website. I put SubSonic.DLL in the asp.net Bin folder and I've generated some classes from SubSonic Commander and put them in a DLL that is also in Bin folder. The problem is the site I'm working on encrypts their connection strings. Can SubSonic 2.2 work with an encrypted connection string? How?

You can use local integrated security and avoid encryption because you have nothing to encrypt.
<add name="ConName" connectionString="Data Source=localhost;Initial Catalog=YourDataBase;Integrated Security=True;" providerName="System.Data.SqlClient" />
By default Subsonic did not have decryption, you can find the DataProvider.cs and add it by your self, or you can use the public SharedDbConnectionScope(DataProvider dataProvider, string connectionString) to make connections with the connection string after you decode it, but I do not think that this can help you in large scale.

Related

Equivalent of web.config in class library

I have three web applications that all access the same database. There is a lot of duplicated code there, so I'd like to move all the common stuff into a new project that each three application can just reference.
Firstly, I assume that a Class Library is the best thing to use to achieve this?
Secondly, where in a Class Library would I store the connection string settings that previously would have been inside web.config?
In ASP.NET I am currently doing the following:
Web.config
<connectionStrings>
<clear/>
<add name="A" connectionString="Persist Security Info=False; User ID=user; Password=pass; Initial Catalog=myDb; Data Source=localhost; Connection Timeout=60" providerName="System.Data.SqlClient"/>
<add name="B" connectionString="Persist Security Info=False; User ID=user2; Password=pass2; Initial Catalog=myDb; Data Source=localhost; Connection Timeout=60" providerName="System.Data.SqlClient"/>
</connectionStrings>
ASP.NET Pages
Dim conn as New SqlConnection(ConfigurationManager.ConnectionStrings("A").ConnectionString)
I've searched for an answer, but can only find answers for accessing a web.config file from within a separate project, which is different.
You have to add an app.config file for configuration. But when reading from a class library, to have to use the app.config situated on the entry point executable project.
Imagine the following projects:
-ClassLibrary.dll (with)
- Class1.vb
- Class2.vb
- SettingsReader.vb
-ConsoleProgram.exe (with)
- Program.vb
- App.Config
Is ConsoleProgram the project where you must put your appSettings (in app.config), and then you can read them using the SettingsReader from the class library.
If you really want to read settings from your dll assembly, you could insert an app.config and set that file as "Embedded resource", so you can read the file using the Assembly.
Something like this:
var assembly = Assembly.GetExecutingAssembly();
var resourceName = "MyApp.App.Config";
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
}

Use AspNetSqlMembershipProvider without connectionStrings in Web.config

We use the following services, which are declared in the Web.config.
AspNetSqlMembershipProvider
AspNetSqlProfileProvider
AspNetSqlRoleProvider
We are using EntityFramework, and now have a requirement to programmatically set the connection string (it is fetched from the deployment environment, so Web.config cannot be used).
The question is, how can we continue to use these Providers, but have a programatic connection string?
We do not want to maintain multiple configs, and we do not want to leave credentials in the Web.config.
Thanks!

Issue with unwanted connection string appearing in my published web config

I’ve been testing the new web deploy tool with VS 2012 but I have this issue:
I get this extra connection string added to my published web config that I don't currently have in my projects web config.
<add name="name" connectionString="name_ConnectionString" providerName="System.Data.SqlClient" />
Where could this be coming from? It seems like is a relic from past conn strings I've used..
Hope this explains my issue :0)
Thanks for any assistance
Quantum
It has to be coming from one of the web.config files.
Have you checked if a transform to your web.config is applied or not. Check web.release.config, web.debug.config file to check if the connection string is still there.

Sharing Entity framework objects across projects?

I am having some refactor troubles, maybe someone knows why...
In one solution I have a WCF service. In another solution I have a RIA application. Since the SQL database between these two is identical, I wanted to create a separate project, in which to host the edmx file as well as a domain service. If I create the edmx file in the WCF project directly, and do the same on the RIA side, everything works fine.
But when I try to pull this edmx file into a separate project and add references to it I get all kinds of bizarre errors that my entity objects cannot be found. The WCF service itself seems fine, in that it references the edmx project and compiles just fine.
But the WCF client project, that has a service reference to the WCF service pukes on the entity references. Even adding the edmx assembly doesnt really help- some entities are found others are not. Very odd.
Anyone know what Im missing?
Copy the connection string across all your projects which attempt to use the model.
However, in the connection string, remove the OR'd Resource pointers.
e.g. Full Entity Connection
<connectionStrings>
<add name="AwesomeEntityModel"
connectionString="metadata=res://*/AwesomeEntityModel.csdl|res://*/AwesomeEntityModel.ssdl|res://*/AwesomeEntityModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=NEILHIGHLEY.COM;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
Trim it to the following;
<connectionStrings>
<add name="AwesomeEntityModel"
connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=NEILHIGHLEY.COM;integrated security=True;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
Based on what you've posted so far and taking it that you've ensured that the "edmx" project has a new namespace that is also used by the other projects.
If I'm reading what you've said correctly:
your WCF server references the "edmx"
project.
your WCF client references the WCF
server AND the "edmx" project.
It could be something as simple as circular referencing conflicts. Make sure that any "edmx" reference data within both of the other projects aren't public, just in case the client is picking up "edmx" data from the server project.
Also check whether missing items are left at the default accessibility of internal (when not defined).

Deployment of encrypted app.config

I've created a console .Net application and encrypted the app.config file with RSAProtectedConfigurationProvider. I've used an article http://www.codeproject.com/KB/dotnet/EncryptingTheAppConfig.aspx as an example for the Encryption. It works fine in an IDE on my XP desktop.
Then I deployed my application to a Windows 2003 server. The package included the app's executable along with the encrypted app.exe.config file. However, the application failed on the server with the following exception:
Unhandled Exception: System.Configuration.ConfigurationErrorsException: Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened.
I decided to encrypt app.config on the server so I copied app.config and encrypted it. The app.exe.config looked encrypted and I ran the application. However, it failed: although it didn't raise an Rsa exception as before, it couldn't read a connection string. After I decrypted app.exe.config, I found that it contained only the below string
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
although the original app.config had contained an application-specific connection string.
I think that in order to resolve my issue I should export the RSA keys from my desktop to the server. Can you advise how can I do it (it's not a Web application!).
Many thanks for your advice.
I've found a solution in the article APP.config encryption with RSA and Deployment.
It is suggested to use custom keys. They are created, exported and imported with the aspnet_regiis utility.
Here are my notes:
It works fine if IIS is installed on the development desktop and the target server. But for my Console application IIS is not needed,
and it may not exist on the server. The author of the article provides a workaround in this case. I've found it a little
complicated and used aspnet_regiis because IIS is installed both on my source and target machines.
After adding the configProtectedData section to my app.config file, Visual Studio created warnings:
The 'keyContainerName' attribute is not declared.
The 'useMachineContainer' attribute is not declared.
The 'description' attribute is not declared.
As per the article Visual Studio throws warnings when sections of Web.Config are encrypted using RSA by Darth Zar, the warnings can be ignored for Web.config.
I've ignored them in my case (for app.config), and everything worked fine.
I hope my post has been useful.