ASP.NET A problem when connect from remote DB to localhost instance - asp.net

I have made the remote database backup (MSSQL Server 2005 Express) to the localhost, and I want to connect with that in my app. To do so, I've changed the connection string:
from
Data Source=190.190.200.100;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
to
Data Source=TOMEK\SQLExpress;Database=myDataBase;User ID=myUsername;Password=myPassword;
but the error appears: Format of the initialization
string does not conform to specification starting at index 0
I can login to the Management studio with that login/pass, and also the user name that I login into sql server has role membership db_owner to that database
what's wrong with that connection string ?

Try one of the 2 options.
Data Source=foo\SQLExpress;Initial Catalog=bar;User Id=user;Password=pwd;
or
Server=foo\SQLExpress;Database=bar;User ID=user;Password=pwd;
They're equivalent, but not sure if you can mix/match
Server/Data Source
Database/Initial Catalog
Are you using a hardcoded string, or from a .config file? Does your username or pwd contain any characters that might need escaping in the .config file? i.e. slash, ampersand?
string connstr = #"Server=foo\SQLExpress;Database=bar;User ID=user;Password=pwd;";
SqlConnection conn = new SqlConnection(connstr);
<add name="ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;Database=bar;User ID=user1;Password=&foo;"
providerName="System.Data.SqlClient" />

Maybe try comparing what you are doing to what is found here:
http://www.connectionstrings.com/sql-server-2005

Related

A network-related or instance-specific error occurred while establishing a connection to sql server error 26 on stimulsoft Report

I use this connection string in my asp.net
<add name="DB_PersonnelEntities"
connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=REGAPP\SQL2014;initial catalog=DB_Personnel;user id=personnel;password=qwe123!;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
and this code for StimulSoft
string connectionstring = ConfigurationManager.ConnectionStrings["DB_PersonnelEntities"].ConnectionString;
string serverlocation = HttpContext.Current.Server.MapPath(string.Empty);
StiReport mystireport = new StiReport();
mystireport.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("DB_PersonnelEntities", connectionstring));
mystireport.Load(serverlocation + "\\Report\\RptPersonnel.mrt");
mystireport.Dictionary.Variables["pid"].Value = id.ToString();
StiWebViewer1.Report = mystireport;
mvList.SetActiveView(vwReport);
The connection string works properly in all SQL connections of the program, except for Stimulsoft Report with the code shown above.
Note: this code and connection work properly for StimulSoft SQL connection and other sql connections on my PC and run from Visual Studio, but when the program is published on the server, the StimulSoft SQL connection shows an error 26.
I changed the connection string like this
<add name="Conn"
connectionString="Data Source=REGAPP\SQL2014;Initial Catalog=DB_Personnel;User Id=personnel;Password=qwe123!"
providerName="System.Data.SqlClient" />
and changed instance name / disabled firewall / checked user permission for procedure.
THANKS FOR HELP
The connection string you showed is an Entity Framework connection string, which I'm pretty sure a third-party reporting tool won't be able to use.
But embedded in that EF connection string is a "raw" ADO.NET connection string - have you tried that??
<add name="Report_PersonnelEntities"
connectionString="Data Source=REGAPP\SQL2014;Initial Catalog=DB_Personnel;User id=sa;password=qwe123!;MultipleActiveResultSets=True;"
providerName="System.Data.SqlClient" />
Word of warning: it is generally recommended NOT to use the sa (system administrator) account which can do literally everything on your server for any programmatic database work - especially not for reporting! Create your own reporting user in SQL Server and use that instead of the all-powerful system admin account!
The StimulSoft Save connection string (in Report.mrt file) That created on my PC. When I Publish My Program, The StimulSoft report Use the connection string embedded in Report.mrt file NOT the web.config.

SQL Server not recognised after hosting the website

I have hosted a website on somee.com and I'm getting the error which says that it is not able to connect to the sql server.
The web.config has the connectionstring as
<connectionStrings>
<add name="RegConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Can anybody let me know the changes I have to make to get this working?
P.S. I have uploaded the database in App_Data folder.
Your connection string still pointing to your local SQL server and even it is local database of your system.
You have to modify your connection strig before publishing the site to the external server/ hosted server.
Change the whole connection string and put below properties within it.
Data Source=value; Initial Catalog=value; User ID = value; Password = value;
Here Data Source will be your SQL Server IP address or URL.
Here Initial Catalog will be your Database name.
You have to put User ID and Password which you are using to your SQL Server (Not Local)
Lose this AttachDbFilename=|DataDirectory|\Database.mdf I have never used it
Try these name value pairs
Data Source=value; Initial Catalog=value; User ID = value; Password = value;

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

SQL Server 2008 connectionString question

I'm trying to connect to my SQL Server 2008 database with ASP.NET MVC 3. Here is my connection string:
<connectionStrings>
<add name="AppConnectionString"
connectionString="Data Source=(local);Initial Catalog=DatabaseName;User Id=UserName;Password=PassWord;"
providerName="System.Data.SqlClient" />
</connectionStrings>
Any idea of what's wrong?
When I try to query something in my DbContext I get this exception:
$exception {"The provider did not return a ProviderManifestToken string."} System.Exception {System.Data.ProviderIncompatibleException}
InnerException {"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"} System.Exception {System.Data.SqlClient.SqlException}
Could someone help me please?
Thanks
First check if your mssqlserver services are running fine. Just run net start mssqlserver in your command prompt.
Then try changing the connection string Data Source=(local) to Data Source=.
All the above is assuming that you have sql server installed in your local machine.
That error means that either the name of your Data Source in your connectionstring is wrong or that your sql server is not configured to allow remote connections : see here how to fix it.
Can you ping the server?
You can create a new empty text file, rename it to test.udl, double click on it and create your connection string that way. (A dialog will open and you can select provider, server, database etc).
also, have a look at www.connectionstrings.com for example connection strings
There is also the instance to take into account. eg if you use sqlexpress it may be (local)\SQLEXPRESS
Besides (local) try (localhost) or 127.0.0.1 (loopback address - and no place like ;-)
Also a single period will "." resolve to the local machine.
Your connection string and the advice above assumes that you are trying to connect to an unnamed, default instance. If your server instance is named then you need to include that as part of your conn string, like: .\ServerName
More great info can be found at: http://connectionstrings.com
I had a similar problem, and these are the steps that helped me:
1) Your application must have an App.config containing a connectionstring named with the same name as your class that inherited from DbContext. In my case "TestEF_CF.ProductContext".
<add name="TestEF_CF.ProductContext" connectionString="Data Source=localhost;Initial Catalog=ef_cf_test;Integrated Security=True" providerName="System.Data.SqlClient" />
2) The database cannot be created before you start to use it. Just set the Initial Catalogue to the name you want Entity Framework to create when it autocreate the database.
See my stackowerflow question for more information if you need it:
Entity Framework 4.1 Code First Freeze
If you look at the InnerException it's possible that what you actually have is a Login issue.
What I had to do to fix this was, change the account the DefaultAppPool runs as, to NetworkService (go to Advanced Settings and change Process Model, Identity) and then pick an account which has access to your database.
Assuming of course your app is running in IIS using the DefaultAppPool.
I made it NetworkService and granted the NT AUTHORITY\NETWORK SERVICE user access to my existing database.
This then allowed me to connect. My case might be specific but I thought I'd share just in case.
SqlConnection [object name];
[object name] = new SqlConnection("Data Source=Server_address/name;Initial Catalog=myDatabase;Integrated Security=True");
[object name].Open();
Note: The square brackets which is shown should not be putted, only object name have to be placed.
Server_address : Your Computer name.
myDatabase : your Database name.

connection string with no user name and password, asp.net

i have a website built in asp.net connecting to a sql 2000 db. within my web.config file, i have a connection string referencing a DSN. in order for my db connection to work i have to include the username and password within the string. for security reasons, is there any way to connect to my db without displaying the username and password. maybe a method to encrypt the information?? the trusted connection string method did not work for me.
current method
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
trusted method (did not work in my server environment)
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
You can encrypt connection strings in your web.config file.
See How To: Secure Connection Strings When Using Data Source Controls on MSDN.
For MySQL with port number
<add name="constring" connectionString="Server=localhost;Uid=root;Database=databasename;Port=3306;" providerName="MySql.Data.MySqlClient"/>

Resources