how can i connect to database from IIS 5.1 - asp.net

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,

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/

Database connection not working in ASP MVC

I just create a new ASP MVC sample. The code was generate with scaffolding. Then I run the application and it runs smooth. But when I click "Register" link in top nav bar and tries to register it does not work.
My Connection String:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-ProductExa‌​mple-20151218101004.mdf;Initial Catalog=aspnet-ProductExample-20151218101004;Integrated Security=True" providerName="System.Data.SqlClient" />
It is saying that your connection with sql server is not established.
Please check your connection string.
Here i am showing mine. Please check it once. It may help you.
<connectionStrings>
<add name="DemoEntities" connectionString="metadata=res://*/Models.Report.DemoEntities.csdl|res://*/Models.Report.DemoEntities.ssdl|res://*/Models.Report.DemoEntities.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.1.2\SQLEXPRESS;initial catalog=DEMODB;user id=abc;password=abc;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Check all following parameters are correct or not.
data source=192.168.1.2\SQLEXPRESS;
initial catalog=DEMODB;
user id=abc;
password=abc;
According to your sql server configuration you need to correct your connection string.
I needed to write IP\InstaceName may be in your you only need to write IP or only instace name. Please check it once.
check sql server express is install or not on your machine if not then use local sql server that is install on your machine and change connection string
data source=.;
initial catalog=DEMODB;
user id=abc;
password=123;

asp.net connection string issue (database is on server side)

I need to connect to server database, hosting support gave me data how to connect:
server=176.9.119.68,3333\sqlexpress;Database=;User ID=;Password=
Right now I created new website (file->new website->asp.net website) and added new item to project (right click -> add new item -> sql server database).
and right now I have connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
what do I need to do to connect to server database: I need to change connection string or I need to change some steps in adding database.
P.S. After I add database, I need to add ado.net entity frameword to connect to this database (I know how to do this when database is inside my project , but may there will be extra steps when database is on the server side?)
Simply replace the existing connection string with your providers one. To test, you can use Sql Management Studio to connect to that server. If gets connection then you can work with remote database in your local projects. Below is the connection string. We too work on similar fashion, for websites and small web based applications. But for enterprise application we prefer Local Development Servers.
<connectionStrings>
<add name="ApplicationServices"
connectionString="server=176.9.119.68,3333\sqlexpress;Database=*******;User ID=******;Password=*****"
providerName="System.Data.SqlClient" />
</connectionStrings>

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 Connection Strings when deploying to a hosting service

I have the following connection strings in development using visual studio web developer 2010 express:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="DatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\BegASPNET\Cheeztest\App_Data\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
<add name="DatabaseEntities" connectionString="metadata=res://*/App_Code.CheeztestModel.csdl|res://*/App_Code.CheeztestModel.ssdl|res://*/App_Code.CheeztestModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
What do I need to change/delete/keep in order to connect to a GoDaddy account with the following parameters:
Host Name: someresource.com
Database Name: databasedb
Username: databasedb
Password: password
I am hosting on a GoDaddy account that only allows a single MS SQL database. In development I had two separate databases; one was ASPNETDB.MDF and the other was Database.MDF. Do I also need to have two separate databases in the hosted environment?
I forgot to mention that yes, GoDaddy does provide a configuration string. I have been trying for two days to make it work without success which is why I am posting here.
The string provided by GoDaddy is:
Data Source=somesource.com; Initial Catalog=databasedb;User ID=databsedb; Password=password;
Also, if necessary I can upgrade my GoDaddy account and get another database. Which I am willing to do if it will make my life easier.
Go Daddy gives you a connection string that you can copy and paste into your web.config that is specific to your database once you set it up. You would just need to make sure you keep the name property the same and you shouldn't have any problems (as long as the DB schema is the same as well).
If you have two databases that you are accessing in your code, you either need to combine them or use two in the hosted environment. Why two in the first place? Is one for the asp.Net users and roles and the other for site data? If that's the case, I would combine them and change my site code to use one connection string.
For your limitation with only one sql database with godaddy one option will be to consolidate your two databases in one.
About the connection strings if you're using visual studio 2010 there's a new feature that allows to make transformations in the web.config based on the build settings so you can have a development and production settings that will transform the web.config automatically. You can find more information about that here, http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyYoureDoingItWrong.aspx
If vs 2010 is not an option then one solution can be to have an application key in your web.config , something like enviroment="development" and then in code when connecting to the database choose the appropiate connection string based on that application setting.
No need to upgrade the plan from Go Daddy or even do not buy extra Database. You can do like, you merge two databases into single database. All the tables from second database will be under first database. Then you can use only one connection string for your multiple applications hosted on same server or different server.

Resources