SQLConnection threw exception of type System.InvalidOperationException

My SqlConnection is causing an error "sqlConn.ServerVersion threw an exception of type System.InvalidOperationException". Everything I have read seems to suggest that there is a problem with my SQLConnection parameters but as you can see from the commeted code below I have tried three different servers with four different configurations.  I am out of ideas on what is causing the error. 

Thanks - Amy

Here is a section of my code:

String sqlStmt = "Select [UserName], [Password], [Last], [First] from Contacts Where Login=@Uid AND Password=@Pwd";

SqlConnection sqlConn = new SqlConnection("Data Source=localhost;Initial Catalog=test;Integrated Security=SSPI;");
//SqlConnection sqlConn = new SqlConnection("Data Source=pe2800;Initial Catalog=test;Integrated Security=SSPI;");
//SqlConnection sqlConn = new SqlConnection("Data Source=HorizonDC02;Initial Catalog=test;Integrated Security=SSPI;");
//SqlConnection sqlConn = new SqlConnection("Data Source=HorizonDC02;Initial Catalog=test;User ID=username;Password=password;");

SqlCommand sqlCmd = new SqlCommand(sqlStmt, sqlConn);
sqlCmd.Parameters.Add(
"@Uid", SqlDbType.VarChar, 30).Value = uid;
sqlCmd.Parameters.Add(
"@Pwd", SqlDbType.VarChar, 30).Value = pwd;
sqlCmd.Connection.Open();

0
ABoggs3354
3/4/2008 10:17:19 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

2 Replies
5400 Views

Similar Articles

[PageSpeed] 59

I m not familiar with Sqldatasource . My guess is connection string missing provider name. Plz check these links

http://msdn2.microsoft.com/en-us/library/aa479307.aspx

http://msdn2.microsoft.com/en-us/library/aa478948.aspx

http://aspnet.4guysfromrolla.com/articles/110905-1.aspx

Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you. 


Thank u

Baba

Please remember to click "Mark as Answer" on this post if it helped you.
0
srijaya_ramaraju
3/5/2008 3:10:52 AM

Ok here is what finally worked.

I changed the code to:

String sqlStmt = "Select [UserName], [Password], [Last], [First] from Contacts Where UserName=@Uid AND Password=@Pwd";
String connString = ConfigurationManager.ConnectionStrings["connWebOrdering"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connString);
SqlCommand sqlCmd = new SqlCommand(sqlStmt, sqlConn);

Put this in the web.config:

<appSettings/>
<connectionStrings>
<
add name="connWebOrdering" connectionString="Data Source=HorizonDC02;Initial Catalog=test;Integrated Security=True" providerName="System.Data.SqlClient" />
</
connectionStrings>

There was a problem with my IP address on my development machine that may have caused problems with permissions on the SQL server but that should not have caused an issue with my local SQL server.

Thanks for the assistance.

Amy

-2
ABoggs3354
3/10/2008 4:05:40 PM
Reply:

Similar Artilces:

Type Initializer for "System.Net.IpAddress" threw an exception
Apologies - I posted this in the GD forum by mistake instead of here... .... System: Windows XP Professional The other day I had a perfect working copy of Web Matrix on which I am developing an MS SQL based package. Then,  two things happened. The first is that my Outlook 2000 Premium was reconfigured to collect and send mail via an Exchange Server as well as my normal POP3 based system.  The second is that a Blue Tooth mouse was installed. Now,  whenever I load a source file into WebMatrix and press the 'F5' key to launch the web server I get this error: "The Type...

Type Initializer for "System.Net.IpAddress" threw an exception
.... System: Windows XP Professional The other day I had a perfect working copy of Web Matrix on which I am developing an MS SQL based package. Then,  two things happened. The first is that my Outlook 2000 Premium was reconfigured to collect and send mail via an Exchange Server as well as my normal POP3 based system.  The second is that a Blue Tooth mouse was installed. Now,  whenever I load a source file into WebMatrix and press the 'F5' key to launch the web server I get this error: "The Type Initializer for 'System.Net.IpAddress' threw an exception" and the following...

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
 Hi all,When i run my project on my own computer, it works fine. But when i deploy it to server, it gives me this error. I can run my other dts and sp, but i get this error on this.. The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception. I googled it but could not find a solution. How can i solve this problem?  Hello sourvil, I'm not sure what the problem is. The following thread explains how you can find out more about the error that is reported: http://blogs.infosupport.com/martijnb/archive/2006/01/27/3582.aspx Jeroen Molenaar.----...

i ve got System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, failed. exception
hi everyone i created windows form user control and i embedded it to asp.net web for , my user control sends mail using by System.Net.Mail library but when i open my web site and click to send button that on my user control  i ve got this exception System.Security.SecurityException: Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.    what can i do ? my best regards ..    Couple of questions: 1) Are you running this from an IIS installati...

Exception type: SoapException Exception of type 'System.OutOfMemoryException' was thrown.
Hi All,  I have developed a web application, Which is hosted on Windows 2003 server, IIS 6.0 with CRM. There are some pages that occasionally start throwing System.OutOfMemoryException and another exception related to storage. Below is the Event viewer log detail: Event Type: WarningEvent Source: ASP.NET 2.0.50727.0Event Category: Web Event Event ID: 1309Date:  3/9/2009Time:  4:55:57 AMUser:  N/AComputer: xyz Description:Event code: 3005 Event message: An unhandled exception has occurred. Event time: 3/9/2009 4:55:57 AM Eve...

Exception of type System.Exception was thrown
Hi, I have been getting this error while trying to display a report with a subreport. Even when if I supply the login credentials this bug appears.I am using Crystal 8.5 and SQL server and the normal reports (without subreports) are working fine, it is just this little bugger that I tried to display now that doesn't work.What does this error mean from a crystal perspective?Any advice? I think, therefore I am...

Exception of type System.Exception was thrown.
I have a strange problem going on. I am running Crystal Report 9 and .NET framework 1.1. In the report I have stored procedure that is being used to display report fields. If any type of casting is done in the stored procedure, an exception is thrown: Exception of type System.Exception was thrown. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [Exception: Exception of type System.Exc...

BlogEngine.net
I have download blogengine.net but when I went to save the setting, i got an error mesg saying, An exception of type 'System.UnauthorizedAccessException' occurred in System.Xml.dll but was not handled in user codeAdditional information: Access to the path 'C:\Documents and Settings\molweb96\Desktop\BlogEngine\BlogEngine.NET 1.2\BlogEngine.Web\app_data\settings.xml' is denied. Anyone encountered this problem before? I have given full permission for app_data folder.My HomePage - www.findingsteve.net"It is more blessed to give than to receive." Acts 20: 35 (NIV, Bible)...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception.
I get this stacktrace at my ExceptionManager. It is caught in the Global.asax, so the exception is unhandled by my code :( We have many visitors and customers. This error occurs at least once a week, and all websites in the same pool are down. Only solution for now is to reset the pool when the error occurs. I know there are more topics on this, and I know MicroSoft is aware of the bug but does not know what to do about it. The bug will still be in the 3.5 release. If anybody has a work around for the fix, or a solution which is acceptable and avoids my customers and visitors ...

the type initializer for "System.Web.CompilationLock" threw an exception
I build a web application using VS2008 Pro. When the project is set to use IIS Web Server then all the aspx pages even Master pages get this error (first line of page) when viewing under VS2008 Design: "the type initializer for "System.Web.CompilationLock" threw an exception" <%@ Page Language="C#" MasterPageFile="~/master/Educ.Master" AutoEventWireup="true" CodeBehind="AdminMain.aspx.cs" Inherits="ESI.forms.admin.AdminMain" Title="Admin Main Page" %> It only happens with IIS Web Server setting. Is ther...

Page.Request threw an exception of type "System.NullReferenceException"
I can't figure out what I am doing wrong here. I have a simple page with 2 buttons, a label (Label1) and a hidden field (curCategoryID). The first button executes the following script:--------document.forms["form1"].elements["curCategoryID"].value = 'sdvs'--------The second button just submits the form, on which I have the following code:-------- protected void Page_Load(object sender, EventArgs e){    if (Page.IsPostBack) Label1.Text = Request.Form["curCategoryID"].ToString();}--------and for some reason the "Request" is throwing a nullReferenceException. Any idea ...

The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception
Hi,All of a sudden I started getting this nasty exception all over the place:The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception. Some relevant observations:* The error started occuring a few hours after the last deployment to the live server, not immediately after. So it basically started occuring of its own accord.* We have recently moved to a new host (a VPS). The error only occurs on that server, not our local server nor at the old host's (which was a shared environment).* The problem is basically the same as this guys:http://w...

HELP! type initializer for "System.Xml.Res" threw an exception.
Running DNN 3.1.0, everything has been great til this morning.  I added a page in a child portal, added a Text/HTML module, edited (pasted) a small script, clicked update and got the following error:An error has occurred.DotNetNuke.Services.Exceptions.PageLoadException: Exception of type System.OutOfMemoryException was thrown. ---> System.OutOfMemoryException: Exception of type System.OutOfMemoryException was thrown. --- End of inner exception stack trace --NEVER MIND..... Whatever it was cleared up in about ten minutes (after I panicked) and seems to be ok....