I have never used Visual Studio 2017 (or previous versions) before and have been asked to work on a project that includes getting information from a sql database. I am trying to open a connection to the database using an external config and then using configSource in my App config. However when I run this code I get an error: The ConnectionString property has not been initialized. I have been doing a bit of research on this but I'm uncertain of some of VS features and syntax. First, does the ConnectionString need to be initialized in the app config or somewhere else like a module or form? Here are my app config and external config code.
External config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="WindowsApp4.My.MySettings.TrakConnectionString"
connectionString="Data Source=Trak;Initial Catalog=Trak;User
ID=TrakMe;Password = TrakMeData;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
App config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings configSource ="external_conn.config"/>
</configuration>
Thank you for any help.
To answer your question
I have always kept my connection strings in the app.config file. I can't think of a good reason to keep it in a separate file, so I would suggest moving it to app.config.
The Data Source should be the address of the server hosting the SQL database. If this is your machine you should use localhost, if it is a dedicated server you could use the server's IP address.
I don't think it could be the spaces around the equal sign for Password but I would get rid of those if only for consistency. Voodoo might be making your password " TrakMeData"
What I would do
Just let VS handle it by using Entity Framework to make the database connection. Right click in your Solution Explorer and select Add > ADO.NET Entity Data Model, enter a name and select EF Designer from database. Create a "New Connection..." and you'll have a handy dandy interface with a "Test Connection" button so you don't have to keep recompiling to see if the connection string in your app.config is correct. Here's a tutorial (that follows a different path to the same result) with pictures! You can probably skip the database creation bit as I'm assuming you already have one up somewhere.
Related
I am using Visual Studio Community 2015 with SSDT 14.0.6121.0.
I created SQL Server Database Project and added a Schema object. Inside of this, I wrote
CREATE SCHEMA [MySchema]
and created a project snapshot. However, when I deploy this DACPAC (using DacFX), I see, that the actual deploy statement is
CREATE SCHEMA [MySchema] AUTHORIZATION='dbo'
It's always 'dbo', regardless of actual executing account, and it leads to deploy failure due to lack of permissions in some cases.
In DACPAC, code is as follows:
<Element Type="SqlSchema" Name="[MySchema]">
<Relationship Name="Authorizer">
<Entry>
<References ExternalSource="BuiltIns" Name="[dbo]" />
</Entry>
</Relationship>
</Element>
Is there a way to tell SSDT, that I don't want AUTHORIZATION to be 'dbo' or any other account?
No - when SSDT needs to create a schema, it explicitly adds the authorization header and adds the user who owns it - if no one owns it then it puts it as dbo. There is nothing in SSDT to control this and it just does it for you.
Generally it is better to be explicit about these things and add a user who will own it, why can't you specify a user?
I'm a bit confused. I built my MVC 3 project which works fine in my development environment and the integrated IIS in Visual Studio 2010.
After deploying it to an IIS 7 it seemed to work, too. Reading does. But when I try to change some database values, it simply does not do anything. It seems to work, but after a reload of the changed values, they aren't changed at all.
Development database is on a local MS SQL Server 2008 and production on a remote Server with SQL Server 2005 (in this case, but the version will differ later on). Is there any difference? The user in the connection string has full rights, since changing works via Management Studio.
The connection string looks like this:
<add name="MyDBEntities"
connectionString="metadata=
res://*/Models.MyDB.csdl|
res://*/Models.MyDB.ssdl|
res://*/Models.MyDB.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=10.90.0.88;
initial catalog=MyDB;
persist security info=True;
user id=foo;
password=bar;
multipleactiveresultsets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
Thanks in advance.
PS: I build the project with Entity Framework 4.1 which is installed on the server. Well, reading does work though...
I would suggest ensuring that you have the correct connection details. The easiest way I can think of would be :
Create a new text file ( f.e. connection.txt )
Rename '.txt' to '.udl'
Double-click the created connection.udl file
Provide all the required connection details, hit 'Test connection' button
If it works, hit 'OK' button, open the file with Notepad - connection string will be inside of your connection.udl file. If it doesn't work - you need to find out proper server details ( check instance name, port number, if your user has the correct permissions )
I have one application "App1" under IIS. Inside "App1" I have another application called "App2", in IIS. They both have web.configs and each needs to read their own.
On one server configuration this is not an issue. On another, it didn't like the fact that the connection string values are in both files.
Would this indicate that the "App1" web.config is first?
Our server guys say that the configuration is the same. Has anyone see this before?
Many of the values in web.config like this are inherited. appSettings and connectionStrings are two such areas where values are inherited.
There is a syntax to remove inherited settings before adding new ones. That should be done in your connectionStrings section, to avoid collisions on what i assume are conn strings with the same name.
<remove name="connstringname"/>
<add name="connstringname" ... />
I've been using config transforms in VS2010 quite a bit lately but am confused as to why some transforms are applied directly to the Web.config in the package but others are stored against a token in SetParameters.xml then applied on publish.
For example, take a Web.config with the following connection string and app setting:
<connectionStrings>
<add name="AutoDeployDb" connectionString="Data Source=(local);Initial Catalog=AutoDeploy;User ID=AutoDeployUser;Password=Passw0rd"/>
</connectionStrings>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
</appSettings>
Then here's the corresponding config transform for the current build configuration:
<connectionStrings>
<add xdt:Transform="Replace" xdt:Locator="Match(name)" name="AutoDeployDb" connectionString="Data Source=MyDevServer;Initial Catalog=AutoDeploy;User ID=AutoDeployUser;Password=s*##Kdsl" />
</connectionStrings>
<appSettings>
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="ChartImageHandler" value="storage=file;timeout=20;dir=d:\inetpub\AutoDeploy\TempImageFiles\"/>
</appSettings>
These are both "Replace" transforms and other than one being a connection string matching on "name" and the other being an app settings matching on "key", to my eye they're identical.
Now look inside the SetParameters.xml file in the resultant package and only the connection string has a setParameter node. In the Web.config of the PackagTmp folder, the app setting transform has already been applied while the connection string has a "$(ReplacableToken_AutoDeployDb-Web.config Connection String_0)" value which is applied only when the package is deployed.
Why is this? Is it something specific to connection strings (or conversely, to app settings)? I appreciate the rationale of this approach, I'm just not clear on why it's applied to some settings and not others.
Can anyone shed some light on this?
This actually has nothing to do with config transforms. I just posted a very detailed blog at http://sedodream.com/2010/11/11/ASPNETWebApplicationPublishPackageTokenizingParameters.aspx. But some info here for you.
In the Web Publishing Pipeline (WPP) we handle connection strings as special artifacts. We will automatically create parameters for you for all connection strings. This is because in many cases when you deploy your app you want to change the connection strings. We do not automatically create parameters for any appSettting value. Now back to your question why do we tokenize the connection strings? We are really doing this to make sure that you do not miss setting the value and then accidentally have your application updating the wrong DB. We do help you by creating those parameters for you. Also you can disable this behavior if you want. You can set the MSBuild property AutoParameterizationWebConfigConnectionStrings to false.
Regarding deployment, there's one significant difference between them. When you import web packages to IIS:
Connection strings will automatically be included in the wizard dialog for further parameterization.
App settings will not be there by default. If you really want to do that, please follow the steps in "Custom Parameterization - Application settings in the web.config file" section of Configuring Parameters for Web Package Deployment
The differentiation creates a responsibility boundary between dev and ops. On one hand, you put parameters of target environment (database, cache, AWS key/secret, etc.) in connection strings that ops needs to take care of. On the other hand, you put irrelevant options in app settings section so ops's burden over specific products and business logic can be relieved.
In my company, one ops guy is often responsible for multiple products. You really can't require them to know as much product knowledge as you do. The less thing they need to pay attention, the happier the life will be.
I wan to know that how to read connection string from app.config using installshield es, though there is an option to import the app.config file XML structure but the problem is the section of the connection is being updated at runtime.
During Upgrade i need to fetch the the app.config file's connection string section is there any way to implement this.
Thanks