I have hosted a website in my local machine IIS. The login page is loading fine, but after I enter the credentials, it is not not redirecting me to the homepage, it just stays on the same login page.
This is the connection string that I am using:
<add name="MyConn" connectionString="server=ajaymeda-pc;database=RoomExpenses;Trusted_Connection=true;"/>
</connectionStrings>
P.S: I have lost the source code and only have the compiled version.
First, ensure that the connection information is correct (server and database name). Then make sure that 'Remote Connections' are enabled in SQL.
Also, since it is .Net, you could grab a .Net decompiler (perform a Google search) that will allow you to decompile the DLLs and view the most of the source code. This is probably your last option, but would allow you to at least view what the page is doing and gives you a starting point if you had to redevelop the site.
use this as connection string if this is the issue as you mention:
<connectionStrings>
<add name="ConnStringDb1" connectionString="Data Source=localhost;Initial Catalog=RoomExpenses;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
UPDATE #1
you call this connection string inside your code like below:
using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStringDb1"].ToString()))
{
try
{}
catch
{}
}
Related
I'm new into MVC applications and I'm trying to learn how to connect to my local DB. I have watched lots of tutorials and I could figure it out how to change my connection string in order for the MVC to access my database. But, if I register on my MVC Application, Visual Studio creates automatically four new tables, besides my TEST database and the new user is inserted in those tables, not in the table I have set/used in connection string. What am I doing wrong? Thanks
Here is my connection string:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=DESKTOP-K6CIG9A;Database=TEST;Trusted_Connection=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Here is how it looks my Server Explorer:
Printscreen
You're going to want to change your connection string to use (LocalDb)\v11.0. You can find more information in this article.
This s the connection String I am using in my local asp.net mvc site, I want to publish the website over a web hosting. They have SQL Instance of .\SQLEXPRESS12 and I have created a database name myapp_db as well. I have created a user with that db also. How can I modify the EF generated Connection String, and will it effect my auto generated models too ?
P.S. I know this question might not be StackOverflow's guidelines, but I would appreciate any help.
<connectionStrings>
<add name="DCHSurgical_DBContext" connectionString="metadata=res://*/Areas.ADMIN.Models.Model.csdl|res://*/Areas.ADMIN.Models.Model.ssdl|res://*/Areas.ADMIN.Models.Model.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=myapp_db;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Just change this part of your connectionString like this:
< ... data source=Server's IP Address,Port;initial catalog=myapp_db;
user id=username that you have created;password=yourpassword;
MultipleActiveResultSets=True;App=EntityFramework""
... />
I've recently found some very old server control code and need to up and running. The problem is I don't know how to connect it to the database. Below is the SQL connection:
SqlConnection sqlConnection = new SqlConnection(this.Page.Application["AuctionDbase"].ToString());
SqlCommand sqlCommand = new SqlCommand();
StringBuilder stringBuilder = new StringBuilder();
My question is do I need a web.config file where it can grab the connection string? I've placed the database on a local SQL server but I don't know if that's the right approach. I've never worked with Server Controls before and trying to get this deployed has been difficult!
Thank you in advance!!
Are you looking at the code snippet and trying to locate where the existing connection string is?
Judging by the code snippet, it doesn't look like it's in the web.config. If it was then i would expect a call to the ConfigurationManager, not Page.Application.
Search the code to see if "AuctionDbase" is being set anywhere.
It's possible that it's being set in the global.asax file if you have one.
Another possibility is in the Project options under Settings.
There are various ways of storing/retrieving connection details.
The connectionStrings element would be the most straightforward way to handle connection strings. The connectionStrings section is dedicated to connection strings and was introduced in .NET 2.0.
If the privacy of your connection credentials is of concern: you should use the connectionStrings section, as it can also be encrypted separately from any other settings.
In the Web.config file you can add:
<configuration>
...
<configSections>
<connectionStrings>
<add name="connectionStringName" connectionString="Data Source=(local);Initial Catalog=DBNAME;User Id=XXX;Password=XXX;" providerName="System.Data.SqlClient" />
</connectionStrings>
<configSections>
...
<configuration>
for more information on connection strings you can learn more here: https://www.connectionstrings.com/sql-server/
and in your code you can get the connection string like this:
string connectionString = System.Configuration.ConfigurationManager.
ConnectionStrings["connectionStringName"].ConnectionString;
I am new to create connection string and application configuration file. I use an example which showed connection to SQL Server CE using file which is what I do not want instead I want to connect to SQL Server 2008 Standard edition.
While exploring about connection string on several links like http://www.connectionstrings.com/sql-server/ i found that the Connection string uses the Property "Data Source = " and in some places it uses "Server=" which is quiet confusing.
Here is what I have in my application configuration file.
<connectionStrings>
<add name="ShareManagement"
connectionString="Data Source=localhost"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I want someone to tell me which properties need be used and what should be their respective values. (I am using default sa user as UserID and a password and using SQL Server authentication mode. My SQL Server database is installed on same machine/server on which my Visual Studio solution / application reside).
Ragards.
You can use either server= or Data Source= (those two are equivalent), and you can use either database= or Initial Catalog= (again: those are equivalent) - take your pick, use whatever you prefer.
But you just need to define at least
server,
database,
either Integrated Security=SSPI (for integrated, Windows authentication) or User id=abc;Password=xxxx for SQL Server authentication
You need at least these three pieces of information.
So if you want to use integrated security (Windows authentication), use this connection string:
<connectionStrings>
<add name="ShareManagement"
connectionString="server=(local);database=AdventureWorks;Integrated Security=SSPI;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
but if you want to use SQL Server authorization for a user John with a password secret, use this connection string:
<connectionStrings>
<add name="ShareManagement"
connectionString="server=(local);database=AdventureWorks;User ID=John;Password=secret;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
Since I'm almost exclusively using these connection strings to connect to a standard relational database server, I personally prefer to use server=.... and database=...... - those just seem more natural, clearer and more intuitive to me. But again: you can also use those other key strings - they're 100% equivalent!
In my opinion, you should use the following connection string:
<add name="MyConnectionString" connectionString="Data Source=Server;Initial Catalog=DatabaseName;Integrated Security=True" providerName="System.Data.SqlClient"/>
Data Source should be as of the server name, and the initial catalogue will represent the database name you have with your sql server 2008 instance. To get logged in via the integrated security can be a better choice if you have not defined a user/password separately for that particular database except 'sa' account.
I know I can create a connection string in the c# class itself, but I am trying to avoid doing that. I want to create the connection in the web.config, which I read is more secure. Nevertheless I couldn't find any example that has the following attributes specified:
Host name
Port
SID
Username
Password
Connection Name
Could anyone help please with creating this in webconfig? I am connecting to oracle DB.
Here is the template:
<connectionStrings>
<add name="{ConnectionName}"
connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;"
providerName="Oracle.DataAccess.Client"/>
</connectionStrings>
Here is one of mine - minus a real TNS name and username and password:
<add name="MSOL" connectionString="Data Source={TNS_NAME};User ID={username};Password={password};pooling=true;min pool size=5;Max Pool Size=60" providerName="Oracle.DataAccess.Client"/>
After adding the connection string to the web.config you can use the following:
System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;
to retrieve the connection string.
It may can help u....
Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;
http://www.connectionstrings.com/oracle
You can investigate what the connection string should be like:
1) Create an empty text file in windows explorer and rename it to X.UDL
2) Double click on it and the datalink provider dialog will appear.
3) Select the provider tab. Find the provider for your data access method and click next.
4) Select your source
5) Test the connection and save it.
6) Compare the contents of X.UDL with your connections string.