database is not connecting in iis - asp.net

I have two database.
<add name="OdonovanTestConnectionString" connectionString="Data Source=ODO-SRV004\;Initial Catalog=OdonovanTest;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="rackleyConnectionString1" connectionString="Data Source=ODO-SRV004\;Initial Catalog=rackleyTest;Integrated Security=true" providerName="System.Data.SqlClient" />
When I host my asp .net application in iis. The first database is connecting which is odonovantest.
But the database rackletTest is not connecting. Both database lies in same sql server.
Can any one give me solution?

you can call your connection string explicitly as code bellow:
string connectionString = SampleApplication.Properties.Settings.Default.rackleyConnectionString1;
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
// put code here
}

Make Sure you are using Windows Authentication or Sql Server Authentication.
In Web.config:
For Sql Server Authentication:
For Windows Authentication:
And then your have to define in codebehind also.

Related

Connection string using local SQL Server

How to write the connection string to local SQL Server database using web.config?
Here is my connection string in web.config. But when I open local/demo, it said:
login failed for user ''.
Actually I'm using Windows authentication, so I thought it doesn't need user and password.
<connectionStrings>
<add name="HRISContext"
connectionString="data source=.;initial catalog=BPSDEMO;Pooling=false;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
If you want to use Windows authentication, then yes, you must not include any user id and pwd in your connection string - just remove those completely. But you must include the Integrated Security=SSPI setting instead.
Try this:
<connectionStrings>
<add name="HRISContext"
connectionString="data source=.;initial catalog=BPSDEMO;Integrated Security=SSPI;MultipleActiveResultSets=True;Pooling=false;persist security info=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>

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/

ASP.NET MVC 4 connection string on server to mdf file on app_data for authentication db

I have mvc4 app on godaddy and I do not want to use their sql server database ....Actually I have exhausted my available number of databases on host
so i uploaded the authentication db file as mdf file to app_data folder but i cant connect the mdf file from my app
i used this conn string
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication3-20151212082404;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20151212082404.mdf" providerName="System.Data.SqlClient" />
it was working on local but not on server
so I changed it to this string
<add name="DefaultConnection" connectionString="Data Source=107.181.46.201\v11.0;Initial Catalog=aspnet-MvcApplication3-20151212082404;Integrated Security=SSPI ;user id=todd password=8534876523745;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication3-20151212082404.mdf" providerName="System.Data.SqlClient" />
but it does not work
how can i connect my .mdf file
my mistake is that i was use a mysql database on godaddy
all what I did is that i create an empty sql server db and edit my connection string with the new db name and user and passwore

ASP.NET MVC, Arvixe hosting web.config

Good evening. I have a asp.net mvc3 web project, with sql server database 2012 and EF5. This site working perfectly on my local machine, but when I upload this to Arvixe web hosting and try to connect to pages which connect to database they print me an error:
Could not determine storage version; a valid storage connection or a version hint is required.
I'm try 2 different connection string, but everything without success:
<add name="PrimaryConnectionString"
providerName="System.Data.SqlClient"
connectionString="Data Source=camellia.arvixe.com;Initial Catalog=MyDatabaseName;Integrated Security=false;User ID=userLogin;Password=userPassword;"/>
<add name="SecondaryConnectionString"
connectionString="Data Source=localhost;Initial Catalog=myDatabaseName;Persist Security Info=true;User ID=userLogin;Password=userPassword;"
providerName="System.Data.SqlClient" />
and in code I'm use next part of code to connect to database:
My Context class
public UniversityContext(string connectionString)
{
Database.Connection.ConnectionString = connectionString;
}
Connect from context in project
private UniversityContext context = new UniversityContext(ConfigurationManager.ConnectionStrings[1].ConnectionString);
I'll try to connect to support, but the're didn't know why isn't working, and I'm very embarrased, Have anyone ideas, because I'm in a blind alley.
Don't you have the ip for the database that they gave you?
i use arvixe too, and my db conn in the web.config goes like this:
<connectionStrings>
<add name="MyDBConnectionString" connectionString="Data Source=65.98.21.152;Initial Catalog=mydatabase;User ID=mydatabaseLogin;Password=010101" providerName="System.Data.SqlClient"/>
</connectionStrings>
Hope this helps

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