How to specify Oracle SID to connectionStrings in web.config? - asp.net

I have an ASP.NET application whose connection to the database seems to fail to open because of the Oracle SID not being specified. I can't find any doc on how to specify it in the connection string. Did anyone have the same problem?

Here is the sample :
<connectionStrings>
<add name="{ConnectionName}"
connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;"
providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
After adding the connection string to the web config you can use
System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;
To retrieve the connection string

Related

Unable to complete operation. The supplied SqlConnection does not specify an initial catalog or AttachDBFileName

I am trying to create an App Service web app in the Azure Portal and to connect the web app to my local on-premises SQL Server database using the new Hybrid Connection feature.
Created a simple ASP.NET application using Visual Studio 2015 and trying to connect to the SQL server Database which is on on-prem. And modified the connection String as follows
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=PRAVEEN,1433; User ID=sa; Password=my_password;"
providerName="System.Data.SqlClient" />
</connectionStrings>
When the application is started its running without any errors as shown in below screenshot1.
But when I try register (enter any record) it throws me with an error as specified in the below Screenshot3....
"https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/" - this is the documentation to which I'm referring to..
So, can anyone from the other end help me out please...
Microsoft SQL Server Management Studio screenshot....
Thank you..
#Praveen,
It is what it says - meaning Initial Catalog is missing in your connection string. It requires the Db name to connect to. You have the servername, SQLUserName, SQLPassword, but missing the DatabaseName it requires. Please change your connection string to include the the DbName as follows
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=YourServerName,1433;Database="YourDbName" UserID=YourId;Password=YourPswd;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Look at this site to configure your connection string appropriately: http://www.connectionstrings.com/store-connection-string-in-webconfig/

Connectionstring in windowsservice

My web application's webconfig file contain following connectionstring.
<connectionStrings>
<add name="TestConnectionString" connectionString="Data Source=ServerIp;Initial Catalog=databasename;Persist Security Info=True;User ID=userid;Password=password"
providerName="System.Data.SqlClient" />
May I know what meaning of Persist Security Info?.What is purpose of it in this case?
In my windows service, class file contain following connectionstring.
connectionString="Server=ServerIp;Database=databasename;MultipleActiveResultSets=True;Integrated Security=false;User Id=userid;Password=password"
I want to add appconfig file for connection and replace above one.Does I need to mention provider name?Here is sample one which I am going to write in app.config file.
<connectionStrings>
<add name="SampleConnectionstring" connectionString="Server=ServerIp;Database=databasename;MultipleActiveResultSets=True;Integrated Security=false;User Id=userid;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
what is meaning of MultipleActiveResultSets?Why it is used here?
From MSDN: Multiple Active Result Sets (MARS) is a feature that works with SQL Server to allow the execution of multiple batches on a single connection. When MARS is enabled for use with SQL Server, each command object used adds a session to the connection.
With regards to Persist Security Info: When set to false or no (strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values including the password. Recognized values are true, false, yes, and no.
More information can be found here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx
Also, here's a great resource for connection strings: http://www.connectionstrings.com/

how can i connect to database from IIS 5.1

When I want to connect to my site database via the local networkŘŚ This message will appear:
Cannot log in to my_server_name/AspNet
My connection string is:
<connectionStrings>
<add name="behbahan_cementConnectionString" connectionString="Data Source=MAYA-1307F9F334\SQLEXPRESS;Initial Catalog=behbahan_cement;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>`
I can't connect to the database?
I'd suggest you first try and establish whether you can connect to the database from outside the web application either via SQL Server Management Studio or by using a .UDL file. I've answered a question on testing a SQL server connection here.
Based on the results of these tests it may become apparent to you what the problem may be. In your case, you are using integrated security (which you would need to be on a domain to use over the network). If you are not on a domain, a username and password may need to be supplied.
Standard way to connect Database as;
<connectionStrings>
<add
name="NorthwindConnectionString"
connectionString="Data Source=serverName;Initial
Catalog=Northwind;Persist Security Info=True;User
ID=userName;Password=password"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
What I can See here is you are messing ;
ID=userName;Password=password"
to connect the database in connectionString. Default username and password should be "root" unless you have changed it.
Try to connect with this detail.
Thanks,

Identity Connection string, from local to host

So I have the following in my local web.config file:
<connectionStrings>
<add name="orangefreshConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\orangefresh.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="orangefreshEntities" connectionString="metadata=res://*/App_Code.Orangefresh.csdl|res://*/App_Code.Orangefresh.ssdl|res://*/App_Code.Orangefresh.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\orangefresh.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I uploaded my website to my host, created my database and attached the necessary files to it (the mdf file and the log file), running a query shows the database has all the right data and is working fine.
The host has given me the following connection string:
workstation id=orangefresh.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxx;data source=orangefresh.mssql.somee.com;persist security info=False;initial catalog=orangefresh
(I blacked out the user/pass details)
This connection string, I'm guessing is the to replace the local "orangefreshConnectionString1" connection string, which I've done. Now I'm left wondering what to replace my Identity connection string with, the "orangefreshEntities" which makes use the Entity Framework.
This obviously results in error on the pages that make use of ADO, all the other pages work fine it seems. Any ideas on what to do with the Entity connection string?
Inside orangefreshEntities, you have a reference to connection string="data source=.\SQLEXPRESS;...
I would change that part with the new connection string.
For the rest you are good to go. Path to the csdl, msl and ssdl will not change.
Fixed:
<add name="orangefreshEntities" connectionString="metadata=res://*/App_Code.Orangefresh.csdl|res://*/App_Code.Orangefresh.ssdl|res://*/App_Code.Orangefresh.msl;provider=System.Data.SqlClient;provider connection string="workstation id=orangefresh.mssql.somee.com;packet size=4096;user id=xxxx;pwd=xxxx;data source=orangefresh.mssql.somee.com;persist security info=False;initial catalog=orangefresh"" providerName="System.Data.EntityClient" />
the trick was putting the connection string in between the $quot marks.

Sql server express and connection string in web.config

i have connection string stored in web.config file but it is giving me the error.
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DbProduct.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
where is the bug in the connection string. i have stored my db DbProduct.mdf in app_data folder. i have never use SQLEXPRESS. so i need guide line. thanks
this AttachDbFilename=|DataDirectory|\DbProduct.mdf
should be AttachDbFilename=|DataDirectory|DbProduct.mdf
You don't need to add \
Have a look at this Using connection strings from web.config in ASP.NET v2.0

Resources