Using SQL Azure in an existing connection setting - asp.net

I have a database on SQL Server 2008. I have an ASP.NET application that uses the Enterprise Library to connect to the database. The configuration to connect to this database currently looks like the following:
<add name="DbConnectionString" connectionString="Server=serverName;Database=DatabaseName;Uid=user.name;Pwd=myPassword;" providerName="System.Data.SqlClient" />
This approach works. I want to move this database to SQL Azure. In the management portal, I have a connection string that looks like the following:
Server=tcp:serverName.database.windows.net,1433;Database=DatabaseName;User ID=user.name#serverName;Password=myPassword;Trusted_Connection=False;Encrypt=True;
How do I format the SQL Azure string so that I can put it in the connectionString value of my configuration setting?
Thank you!

My connection string is a format like:
Password=MyPassword;Persist Security Info=True;User ID=MyUsername;Initial Catalog=MyDatabase;Data Source=n65hf24eep.database.windows.net

Related

azure connection string format - adding in azure

I am rebuilding a web app in Azure, I used to have all my app settings and connection strings in azure. So I have put the app settings back in, but the connection string for the Azure SQL server doesn't like what I am putting in.
In the web.config I have this
<add name="LeisureInsureEntities" connectionString="metadata=res://*/LeisureModel.csdl|res://*/LeisureModel.ssdl|res://*/LeisureModel.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:leisureinsure.database.windows.net,1433;initial catalog=leisureinsure-website-preprod;persist security info=True;user id=XXXXXX;password=XXXXXX;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
But I am having issues putting this into the value input field in azure.
You probably don't need the metadata information here. When I work with EF in Azure, I just use the connection string from the portal. e. g.:
data source=tcp:leisureinsure.database.windows.net,1433;initial catalog=leisureinsure-website-preprod;persist security info=True;user id=XXXXXX;password=XXXXXX;multipleactiveresultsets=True

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/

Data source for connection string in Web.config

I was wondering what should be the data source for the connection string in Web.config
My SQL Database explorer looks like 198.57.59.70(SQL Server 10.50.1600 - RAM\ServerAdmin) under which i have databases. When i use this, i get as Network to the database does not exists. When i use Data Source=198.57.59.70, i get an error "System.Data.SqlClient.SqlException: Login failed for user 'RAM\IWPD_3"
This is in asp.net 3.5 in Windows server 2008 for deployment. Thank you!
Can some one guide me, Thank you!!
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=198.57.59.70(SQL Server 10.50.1600 - COMM\ServerAdmin);Initial Catalog=Tracking;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
</connectionStrings>
For me Connection strings could be hard to remember.
Its very easy to make a mistake when you write it manually.
One advice is to use the server explorer to connect to your database. Then right click on your database icon > select properties ... you will see the connection string copy and paste .
VoilĂ !
If you still have problem then remove the integrated security setting
Server Explorer:
Properties:
For SQL if you're using integrated security, your connection string data source should just be the computer name (or IP address) or the computer name IP\instance name if you're running named servers. You shouldn't need "(SQL Server 10.50.1600 - COMM\ServerAdmin)" in the data source.
Also, make life a little easier and don't name it "ConnectionString," as this is redundant. Instead, describe the resource you're connecting to. Assuming the IP is correct and your server is allowing remote connections, your connection string should look something like this:
<add name="TrackingDataStore" connectionString="Data Source=198.57.59.70;Initial Catalog=Tracking;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

SQL Server connection string woes

After spending 6 hours today to get a connection with my SQL Server 2012 database from Visual Studios 2012, I give up.
Setup:
Database: App_Data/GameDB.mdf
DB Location: C:\Users\USERNAME\Documents\Visual Studio 2012\Projects\ProjectRawWar\ProjectRawWar\App_Data\GameDB.mdf
Connection string:
<add name="LocalSqlServer"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=GameDB;Integrated Security=False;"/>
I first tried a SQL Server Compact database, didn't work.
I tried many other connection strings from connectionstrings.com, didn't work.
I tried to put the full path of the database in the connection string, didn't work.
Can someone please help me out of my misery?
Update:
I just followed http://msdn.microsoft.com/en-us/library/aa983322.aspx.
The database is there. I copied the connection string from the wizard right into my webconfig connectionstring, still doesnt work. Why? Where is the logic?
Reading your question I am getting the feeling that you are trying to connect to a database file. While you can do that with Access "Databases" it is not possible with SQL Server databases. The file needs to be mounted or attached to SQL Server first.
Check out this MSDN article for details: http://msdn.microsoft.com/en-us/library/ms190209.aspx#SSMSProcedure
If you're going to disable integrated security, then you need to provide a username and password.
IE:
Server=127.0.0.1;User ID=useridhere;Password=passwordhere;database=dbnamehere
Be sure to make sure the userid and password you specify has access to the database you need. For testing, you can use the 'sa' account, but that's a poor long-term solution for major security reasons.
Ok I fixed it myself.
How I did it:
Delete every .sdf and .mdf file.
Just made following connection strings:
`<add name="DataContext"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\GameDB1.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="LocalSqlServer"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\GameDB1.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />`
Visual Studio created my database using my DBContext.
Thanks all for the information.

SQL Server Express 2008 connection string

I am trying to configure my connection using SQL Server Express 2008.
Can anyone help me please. My server name is as follows: test\expressql2008 and my database is TestDatabase
My connectionstring is :
<add key="hibernate.connection.connection_string"
value="Server=localhost\EXPRESSQL2008;Database=TestMyproject;User=Me;Pwd=test;" />
It seems that the connections isn't working and I get the error:
NHibernate.ADOException : cannot open connection
Here's all connectionstrings needed
http://connectionstrings.com/
<add name="SD_ConnectionString" connectionString="Data Source=[SQLEXPRESS NAME];Initial Catalog=TestDatabase;User ID=[USERNAME];Password=[PASSWORD]" providerName="System.Data.SqlClient"/>
string con = ConfigurationManager.ConnectionStrings["SD_ConnectionString"].ToString()
Can you provide more detail about this error there could be number of reasons
1- Please check ASP.NET user has access to your database if you are using trusted connection.
2- It could be better if you create a SQL USER and assign it permission of DBOWNER to your database and with your connection use that user information.
con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
in web.config

Resources