Hello,
So I am just getting started with .NET,
I am using Visual Web Developer 2005 Express and
SQL Server 2005 Express on XP Media Center (same as XP Pro)
ASP.NET version 2.0.??
Anyways, I am having the time of my life figuring out how to connect to SQL Server from within my C#, as follows,
(wheresettings.connection = ".\SQLEXPRESS;Database=MyDatabase;Integrated Security=SSPI;" in my web.config)
SqlConnection conn = new SqlConnection(Settings.Connection);
SqlDataReader rdr = null;
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("select * from mytable", conn);
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
the above yields unspeakable errors, namely
<font color="red"><b>Cannot open database requested by login. login failed for user 'computername/SQLEXPRESS'</b></font> , etc
AND
<font color="red"><b>A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)</b></font>
If you have ANY information on the suspect, please, please report it to me. Greatly appreciated!
Thanks, Cam
I suggest that you 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.
You can also look on http://www.connectionstrings.com/ for examples of connection strings
No comments:
Post a Comment