Getting "Integrated Security is an invalid attribute error " despite not specifying it - asp.net

I use ASP.NET for web and Oracle for the database. For communicating between ASP.NET and Oracle I use ODP.NET. I have specified the connection string in web.config file as such:
<connectionStrings>
<add name="main" connectionString="Data Source=AGAPUSTEST; User Id=agapus;Password=pswd;"/>
</connectionStrings>
When I try to establish connection using this connection string I get "Integrated Security is an invalid connection string attribute" error. As you can see I have not specified this attribute in the configuration file. So at some point this attribute probably gets added automatically.
I used to have the connection string hard coded and I didn't have any problems at all. Do you have any ideas how to solve this?

Luckily I have found the solution. I'd provided the web config content but I had not given you the code I use to access the connection string from code behind. Here's the code:
string conString = ConfigurationManager.ConnectionStrings[0].ConnectionString;
As I was suspecting Integrated Security attribute being added automatically I was almost sure that some other connection string was retrieved. I tired changing ConnectionStrings[0] to ConnectionStrings["main"] and voila, it worked. So although there's only one connection string in the configuration file, the 0th one is not the one I needed. When I displayed the 0th connection string look what I got:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
I'm sure you guessed where it comes from, from the machine.config file. So to make everything clean and safe I've once more been convinced that accessing by name is most of the time a better idea.

Looks like they are talking about this problem here:
https://community.oracle.com/thread/585813?tstart=405
Seems the solution could be to use User Id=/ in the connection string and see if that works
Also make sure to have your sqlnet.ora have "SQLNET.AUTHENTICATION_SERVICES = (NTS)"

Related

Setting EF Connection String in Azure Web App

We have an ASP .NET (MVC) app and are using Entity Framework 6 to connect to our databases. The DbContext is constructed in a standard way and it loads the connection string on our behalf. The generated code looks like this:
public partial class MyContext : DbContext
{
public MyContext(string connectionName)
: base("name=" + connectionName)
{
}
}
We set the connection string in a local web.config also in a standard way:
<configuration>
<connectionStrings>
<add name="DefaultConnection"
connectionString="metadata=...;provider connection string="...""
providerName="System.Data.EntityClient" />
When we publish the app to Azure we navigate to the Azure Portal, then to the Web App's Settings, then to the list of Connection Strings. There we add the EF connection string that we had used locally. When we restart and visit the app we get a run-time error depending on the type of connection string we choose.
For a Custom type we get the following run-time error:
Keyword not supported: 'data source'.
For SQL Server or SQL Database we get the following run-time error:
Keyword not supported: 'metadata'.
This really seems like a straightforward story so we are wondering what is going wrong.
The problem is the escaped quotes: ".
The connection strings in web.config have quotes escaped because they are serialized in an XML attribute. When entering a connection string in the Azure portal you should provide the raw unescaped string. Something like this:
metadata=...;provider connection string="Data Source=..."
David Ebbo's answer is good for confirming that the Environment is set up as you expect. It is also helpful to pay attention to the .pubxml file when publishing via the wizard in Visual Studio: it will try to populate connection strings as well.
'custom' should be correct here. In that case, the providerName is left unchanged, so if you have System.Data.EntityClient in your config, that should remain after the Azure runtime changes it.
Try going to Kudu Console and click on Environment to make sure the conn string looks correct there.
If you have this line in web.connfig
<add name="Entities" connectionString="metadata=res://*/TestDB.csdl|res://*/TestDB.ssdl|res://*/TestDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=XXXXXXXX.database.windows.net,1433;Initial Catalog=YourDB;User ID=YourUser;Password=XXXXXX"" providerName="System.Data.EntityClient" />
Add this in azure portal:
Name Column => Entities
Value Column => metadata=res://*/TestDB.csdl|res://*/TestDB.ssdl|res://*/TestDB.msl;provider=System.Data.SqlClient;provider connection string="Data Source=XXXXXXXX.database.windows.net,1433;Initial Catalog=YourDB;User ID=YourUser;Password=XXXXXX"
"Custom" - In the drop selection box
Make sure (as stated in first answer) to replace " with "
Just recording my own experiences in addition to answers already recorded here
This was my final connection string (on mutliple lines for clarity)
metadata=res://*/Models.mBT.csdl|res://*/Models.mBT.ssdl|res://*/Models.mBT.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=tcp:myazureserver.database.windows.net,1433;
Initial Catalog=databasename;
User ID=z#myazureserver;
Password=xyz"
To convert from a "normal" connection string to one that is accepted by EF:
The connection string type in the application settings has to be "other" not "SQL Azure"
The connection string value automatically replaces anything published in web.config
The metadata name Models.mBT.csdl (and the other two) comes from this:
Firstly, mBT is the name of my .edmx file
With regards to the Model. bit, see the answer from #leqid here: MetadataException: Unable to load the specified metadata resource
You can inspect your obj directory and see these three metadata files are in a subfolder called Models, so you need to prepend with Models.

Getting the object reference must be set to an instance of an object in Generic Handler

I am trying to read some image data from my sql database, i have it writing; all i need to do is get it reading. But i am getting the error stated in the question on line 18? Can somone please help me.
Here is the code:
http://codepad.org/d3Yd702T
Do you have a connection string named RevisionConnectionString in your web.config file?
In your web.config file, add the following in the <configuration> section:
<connectionStrings>
<add name="RevisionConnectionString" connectionString="whatever it should be for you;" />
</connectionStrings>
Property ConfigurationManager.ConnectionStrings gets the ConnectionStringsSection data for the current application's default configuration.
A ConnectionStringsSection object contains the contents of the configuration file's connectionStrings section.
And configuration file is your web.config, which means that in it you should have section where is stated conn string as a relation to data source.
So, first check is there a connection string, and if is, check is name written properly.
Line 18 shows this:
string strConnection = ConfigurationManager.ConnectionStrings["RevisionConnectionString"].ToString();
Which can only mean that you don't have a ConnectionString with key RevisionConnectionString

problem in connectionstring in asp.net

private string conString = "Data Source=173.56.33.6;Database=musicapp;User ID=guest;Password=guest";
I was working on local database at that time my application was successfully interacting with mysql database.when put the database on server, my application still taking the old connection string and data is stored in local database and not on server.
what is wrong?
I'd remove hard coded connection strings all together. There is a dedicated section of your config file for this very purpose:
<connectionStrings>
<add name="MusicApp" connectionString="Data Source=173.56.33.6;Database=musicapp;User ID=guest;Password=guest;" />
</connectionStrings>
Which you can then read out:
string connection = ConfigurationManager.ConnectionStrings["MusicApp"].ConnectionString;
I think your problem is that you have the connection string hard-coded in your code (as a private string that you show above). A much better way is to store it in the config file, use Settings in VS and select ConnectionString as type.
Make sure whether you updated your connection string when you transfered your DB to server. In any case it is best to store connection string in web.config, so that you can modify it when ever your db is changed or transferred to another location. This change in connection string in your web.config wouldn't require you to rebuild your application. Although if your connection string is hard-coded in code, then you would require to rebuild your application when ever you change the connection string.
if Data Source=173.56.33.6; is the location of your server database try this instead Data Source=\173.56.33.6;

Format of the initialization string does not conform to specification starting at index 0. Unsure What This is?

I'm building a website, and I am trying to create a connection to the database. Here is the Connection code in my web.config file:
<add name="DBX" connectionString="Data Source=localhost;Initial Catalog=DATABASE;User Id=USER;Password=PASSWORD" providerName="SqlDataSource" />
And this is the code I'm using in the code behind page:
Protected Conn As New System.Data.SqlClient.SqlConnection("DBX")
When I go to view the web page, I get the following error:
Format of the initialization string
does not conform to specification
starting at index 0.
And this highlights the Connection string in the VB.NET code behind page. I've checked the details of the original connection string contained within the web.config file, and I've used the ConnectionStrings.com website for the actual code. I'm at a loss to explain or to figure out why this isn't working?
Many thanks!
"DBX" is not the correct format for a ConnectionString ;-)
What you really wanted is the ConnectionString section of your DBX-Connection in the web.config:
Protected Conn As New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("DBX").ConnectionString)

SQL Express connection string hell ASP.Net

SQL Express 2005 is running locally. I have a project written by another person running on the same machine. All I want to do is connect to it, can't be that hard right?
This is the one I use in my old classic ASP code to hit another database running on the same instance:
Provider=SQLOLEDB;Data Source=MYLAPTOP\MSSMLBIZ;Persist Security Info=True;User ID=TestUser;Password=letmein;Initial Catalog=TestDB
But trying a version of that makes the .net code throw a wobbler as he's written it using SQLServer drivers so its not liking the Provider stuff.
Here is the orginal connection string from his code:
Server=(local);Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;
I've been to http://www.connectionstrings.com/sql-server-2005 and tried several of the options from there, these all get "SQL Server does not exist or access denied" (what a lovely mixed error message that is!):
Data Source=localhost;Integrated Security=True;Initial Catalog=TheDatabase
Data Source=localhost\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
Data Source=MyLaptop\SQLEXPRESS;Integrated Security=True;Initial Catalog=TheDatabase
Server=MyLaptop\SQLEXPRESS;Initial Catalog=TheDatabase;User Id=TheUser;Password=ThePassword;
I've created logins for MyLaptop/IUSR_MyLaptop, MyLaptop/ASPNET, MyLaptop/IWAM_MyLaptop in SQL Express and given them all read/write permissions to my DB and set their default DB to be TheDatabase.
What the heck am I doing wrong and how can I debug the problem some more?
UPDATE: Special Thanks to Chris for all his pointers, got there in the end, if you are having similar problem please read all the comments there are lots of links and tips on how to track them down.
Can you advise exactly what is in the config?
Are you using the block - in which case a valid connection string would be:
<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=True" />
or
<add name="connection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost\MSSMLBIZ;Initial Catalog=TheDatabase;Integrated Security=False;User Id=TheUser;Password=ThePassword;Application Name=AppName;" />
Or are you getting the connection string from app settings - in which case I guess your provider is set in code inside the app itself?
With that error message in your comment you should run through the items in http://blogs.msdn.com/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
I presume the instance is running and does allow connections over tcpip?
Shouldn't your datasource read: Data Source=localhost\sqlexpress too?
You don't mention granting rights for 'TheUser' to access the database on the server - if you're restored from another server you may had a sid mismatch.
Try running
sp_update_users_login 'report'
against the db in question.
If it returns the user account in the report try:
sp_update_users_login 'update_one', 'theuser', 'theuser'
to remap things.

Resources