What is wrong with this connection string? - asp.net

Hai guys,
I use the following connection string
<add name="connectionString" connectionString="server=localhost;user id=root; password=; database=lms; pooling=false;" providerName="MySql.Data.MySqlClient"/>
It gives me the error There is no 'lms'#'%' registered.
My database server is localhost and the user account doesn't have a password..

Here's a working connection string for MySql:
server=localhost;user id=root;password=xxx;database=xxx;pooling=false
Can you connect from the command line (using "mysql")?
Is mysql by any chance bound to a different IP other than localhost (in my.ini)?
If you don't have a password, have you tried leaving off password=?
If that doesn't work, you may have to add a password....

F0r MySql, should be something like:
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword

Shouldn't it be something like:
<add name="ConnString" connectionString="Database=lmz;Data Source=localhost;User Id=root;Password=;CHARSET=utf8;" providerName="MySql.Data.MySqlClient"/>
Also check that the user has permissions to the database.

Related

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;

Proper format for SQL Server Connection String on 1and1.com

I have spent several hours trying to search this on the web in addition to calling and emailing support at 1and1.com web hosting with no success.
I have ASP.NET pages which connect to MS SQL Server database using the entity framework. On my local machine, all works fine (naturally). However, when I modify the connection string in my web.config to point to my SQL Server database on 1and1.com, I get the following error:
"Unable to load the specified metadata resource."
Here's my current connection string (as defined in my web.config file):
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/
Model1.csdl|res://*/
Model1.ssdl|res://*/
Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;multipleactiveresultsets=True"" />
(Please note that where there are 'XXXX' the values are different in the actual config file as well as for 'database_name' and 'valid_password')
I'm using the Entity Framework in the code so I'd prefer solutions that correct the content of my web.config file.
Here is what ended up working for me:
<add name="TimeDataLicenseEntities"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://<assemblyname>/Model1.csdl|
res://<assemblyname>/Model1.ssdl|
res://<assemblyname/Model1.msl;
provider=System.Data.SqlClient;
provider connection string="
data source=dbXXXX.db.1and1.com,1433;
Integrated Security=false;
initial catalog=database_name;
user id=dboXXXX;
password=valid_password;
multipleactiveresultsets=True"" />
By including the assemblyname for my code in the sections above (the brackets ('<' and '>') should not be included), I was able to finally get it to work.
Thanks all for your assistance.
Here is what actually works on 1and1 server from ASP.NET Code first design. So, simply replace your serverName, DatabaseName, UserID, and Password.
<add name="DefaultConnection"
connectionString="Data Source=dbXXX.db.1and1.com,1433;Initial Catalog=dbYYYYY;Integrated Security=False;user id=dboZZZZZ;password=YOURDBPASSWORD;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />
Hope this can help anyone looking to use 1and1 asp.net server since their customer service is pretty useless.

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,

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.

Resources