Forum Moderators: open
1. Is it possible to build a C# component 'Conn.cs', with these 2 methods
- OpenConn - to establish databse connection
- CloseConn - to close database connection?
which will be called everytime my .aspx needs to open n close MSSQL connection?
... and how to close the connection? is there any examples / URL?
2. The system will work with MS Sharepoint, which require Windows Authentication login.
- So, what is the ADO.net connection syntax using c#? where do i put the username? and what if the SQL server resides on other machine (lets say SQL server : PC15/SHAREPOINTPORTAL) how to put it in the syntax because i encountered some errors on that line.
I tried something like this example ...
------
public class Conn
{
public void OpenConn()
{
SqlConnection mySqlConnection = new SqlConnection("server=(local)\\NetSDK;Trusted_Connection=yes;database=northwind");
//what if i set login to windows authentication?
try
{
mySqlConnection.Open();
//opened
}
catch
{
//fail
}
}
public void CloseConn()
{
// mySqlConnection.Close();
// how to 'TAKE' the existing connection and close it?
}
}
----
Thank you very much!
First off your conn.cs that provides connection methods: Rather than having that class open/close, just create a Public Property that returns a connection object that is ready for use but not open. You calling class can perform the .open/.close/set to nothing. Each ASPX page imports that class.
On the trusted connection front, one of the advantages of using Trusted Connections is so you don't have to put a user/pass in the connection string. The aspx page is being executed by the ASP.NET user account so that would have to be the trusted account. For trusted connections across servers, both boxes must be in the same domain and the user account that is trusted must be a domain account. Since the ASP.NET user account is a local account, I'm not sure how you can port this over or if it's possible.
From M$FT:
Note If your application uses Internet Information Server, you probably will not use SQL Server integrated security.
I did find an article on authentication and security that may help some HERE [msdn.microsoft.com]
Quack Quack!