Showing posts with label writing. Show all posts
Showing posts with label writing. Show all posts

Monday, March 19, 2012

"SQL Server Mobile encountered problems when opening the database."

Hi,

I am writing an application for a device (HP IPAQ 6828) having Windows Mobile 5.0 using

-MS .NET Compact Framework 2.0 SP-1
-SQL Mobile 2005.
-VS 2005 .NET

The application uses Merge Replication. The error occurs in the Synchronise() Method of the SqlCeReplication object.

"SQL Server Mobile encountered problems when opening the database."

repl.AddSubscription(AddOption.ExistingDatabase)
repl.Synchronize()

I also checked the the connection string and it seems to be fine. Both my device and server can ping each other. Moreever I can also access the Web syncronization folder(on server) from the device.

Is anyone having a resolution for this?


This problem may be caused by many reasons.

The most common is not disposing the replication object or other data related objects. Make sure there isn't any other arround.
Sql Mobile 2005 allows multiple connections except while syncronizing.

Another known cause is a bad path on the connection string.

Other forum entries referring this problem:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=334604&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=478902&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=961633&SiteID=1|||

Hi,

I finally found the solution to this...

repl.AddSubscription(AddOption.ExistingDatabase)
repl.Synchronize()

(Note: I am trying to synchronize on an exisiting database)

The problem was since my database is already in use by my application and I am trying to sync the same DB. Synchronization cannot occur if the connection is already open by the application. Sql Mobile 2005 allows multiple connections except while synchronizing.

Therefore we need to close and dispose the open connection used by the application as under before attempting to synchonize.

(Below is the sample code)

private sub SampleSync()

sharedCon.close
sharedCon.dispose

try

' TO DO: Set replication object properties here

repl.AddSubscription(AddOption.ExistingDatabase)
repl.Synchronize()

finally
repl.dispose
end try

' TO DO: Open your shared connection here if required.

End sub

Note: Most of the times the connection string also causes a problem. A sample connection string would look like this...

repl.SubscriberConnectionString ="\Program Files\YourAppName\YourDb.sdf;Password =<...>"

Saturday, February 25, 2012

"Command text was not set for the command object" Error

Hi. I am writing a program in C# to migrate data from a Foxpro database to an SQL Server 2005 Express database. The package is being created programmatically. I am creating a separate data flow for each Foxpro table. It seems to be doing it ok but I am getting the following error message at the package validation stage:

Description: An OLE DB Error has occured. Error code: 0x80040E0C.

An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E0C Description: "Command text was not set for the command object".

.........

Description: "component "OLE DB Destination" (22)" failed validation and returned validation status "VS_ISBROKEN".

This is the first time I am writing such code and I there must be something I am not doing correct but can't seem to figure it out. Any help will be highly appreciated. My code is as below:

private bool BuildPackage()

{

// Create the package object

oPackage = new Package();

// Create connections for the Foxpro and SQL Server data

Connections oPkgConns = oPackage.Connections;

// Foxpro Connection

ConnectionManager oFoxConn = oPkgConns.Add("OLEDB");

oFoxConn.ConnectionString = sSourceConnString; // Created elsewhere

oFoxConn.Name = "SourceConnectionOLEDB";

oFoxConn.Description = "OLEDB Connection For Foxpro Database";

// SQL Server Connection

ConnectionManager oSQLConn = oPkgConns.Add("OLEDB");

oSQLConn.ConnectionString = sTargetConnString; // Created elsewhere

oSQLConn.Name = "DestinationConnectionOLEDB";

oSQLConn.Description = "OLEDB Connection For SQL Server Database";

// Add Prepare SQL Task

Executable exSQLTask = oPackage.Executables.Add("STOCK:SQLTask");

TaskHost thSQLTask = exSQLTask as TaskHost;

thSQLTask.Properties["Connection"].SetValue(thSQLTask, "oSQLConn");

thSQLTask.Properties["DelayValidation"].SetValue(thSQLTask, true);

thSQLTask.Properties["ResultSetType"].SetValue(thSQLTask, ResultSetType.ResultSetType_None);

thSQLTask.Properties["SqlStatementSource"].SetValue(thSQLTask, @."C:\LPFMigrate\LPF_Script.sql");

thSQLTask.Properties["SqlStatementSourceType"].SetValue(thSQLTask, SqlStatementSourceType.FileConnection);

thSQLTask.FailPackageOnFailure = true;

// Add Data Flow Tasks. Create a separate task for each table.

// Get a list of tables from the source folder

arFiles = Directory.GetFileSystemEntries(sLPFDataFolder, "*.DBF");

for (iCount = 0; iCount <= arFiles.GetUpperBound(0); iCount++)

{

// Get the name of the file from the array

sDataFile = Path.GetFileName(arFiles[iCount].ToString());

sDataFile = sDataFile.Substring(0, sDataFile.Length - 4);

oDataFlow = ((TaskHost)oPackage.Executables.Add("DTS.Pipeline.1")).InnerObject as MainPipe;

oDataFlow.AutoGenerateIDForNewObjects = true;

// Create the source component

IDTSComponentMetaData90 oSource = oDataFlow.ComponentMetaDataCollection.New();

oSource.Name = (sDataFile + "Src");

oSource.ComponentClassID = "DTSAdapter.OLEDBSource.1";

// Get the design time instance of the component and initialize the component

CManagedComponentWrapper srcDesignTime = oSource.Instantiate();

srcDesignTime.ProvideComponentProperties();

// Add the connection manager

if (oSource.RuntimeConnectionCollection.Count > 0)

{

oSource.RuntimeConnectionCollection[0].ConnectionManagerID = oFoxConn.ID;

oSource.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.ToConnectionManager90(oFoxConn);

}

// Set Custom Properties

srcDesignTime.SetComponentProperty("AccessMode", 0);

srcDesignTime.SetComponentProperty("AlwaysUseDefaultCodePage", true);

srcDesignTime.SetComponentProperty("OpenRowset", sDataFile);

// Re-initialize metadata

srcDesignTime.AcquireConnections(null);

srcDesignTime.ReinitializeMetaData();

srcDesignTime.ReleaseConnections();

// Create Destination component

IDTSComponentMetaData90 oDestination = oDataFlow.ComponentMetaDataCollection.New();

oDestination.Name = (sDataFile + "Dest");

oDestination.ComponentClassID = "DTSAdapter.OLEDBDestination.1";

// Get the design time instance of the component and initialize the component

CManagedComponentWrapper destDesignTime = oDestination.Instantiate();

destDesignTime.ProvideComponentProperties();

// Add the connection manager

if (oDestination.RuntimeConnectionCollection.Count > 0)

{

oDestination.RuntimeConnectionCollection[0].ConnectionManagerID = oSQLConn.ID;

oDestination.RuntimeConnectionCollection[0].ConnectionManager = DtsConvert.ToConnectionManager90(oSQLConn);

}

// Set custom properties

destDesignTime.SetComponentProperty("AccessMode", 2);

destDesignTime.SetComponentProperty("AlwaysUseDefaultCodePage", false);

destDesignTime.SetComponentProperty("OpenRowset", "[dbo].[" + sDataFile + "]");

// Create the path to link the source and destination components of the dataflow

IDTSPath90 dfPath = oDataFlow.PathCollection.New();

dfPath.AttachPathAndPropagateNotifications(oSource.OutputCollection[0], oDestination.InputCollection[0]);

// Iterate through the inputs of the component.

foreach (IDTSInput90 input in oDestination.InputCollection)

{

// Get the virtual input column collection

IDTSVirtualInput90 vInput = input.GetVirtualInput();

// Iterate through the column collection

foreach (IDTSVirtualInputColumn90 vColumn in vInput.VirtualInputColumnCollection)

{

// Call the SetUsageType method of the design time instance of the component.

destDesignTime.SetUsageType(input.ID, vInput, vColumn.LineageID, DTSUsageType.UT_READWRITE);

}

//Map external metadata to the inputcolumn

foreach (IDTSInputColumn90 inputColumn in input.InputColumnCollection)

{

IDTSExternalMetadataColumn90 externalColumn = input.ExternalMetadataColumnCollection.New();

externalColumn.Name = inputColumn.Name;

externalColumn.Precision = inputColumn.Precision;

externalColumn.Length = inputColumn.Length;

externalColumn.DataType = inputColumn.DataType;

externalColumn.Scale = inputColumn.Scale;

// Map the external column to the input column.

inputColumn.ExternalMetadataColumnID = externalColumn.ID;

}

}

}

// Add precedence constraints to the package executables

PrecedenceConstraint pcTasks = oPackage.PrecedenceConstraints.Add((Executable)thSQLTask, oPackage.Executables[0]);

pcTasks.Value = DTSExecResult.Success;

for (iCount = 1; iCount <= (oPackage.Executables.Count - 1); iCount++)

{

pcTasks = oPackage.PrecedenceConstraints.Add(oPackage.Executables[iCount - 1], oPackage.Executables[iCount]);

pcTasks.Value = DTSExecResult.Success;

}

// Validate the package

DTSExecResult eResult = oPackage.Validate(oPkgConns, null, null, null);

// Check if the package was successfully executed

if (eResult.Equals(DTSExecResult.Canceled) || eResult.Equals(DTSExecResult.Failure))

{

string sErrorMessage = "";

foreach (DtsError pkgError in oPackage.Errors)

{

sErrorMessage = sErrorMessage + "Description: " + pkgError.Description + "\n";

sErrorMessage = sErrorMessage + "HelpContext: " + pkgError.HelpContext + "\n";

sErrorMessage = sErrorMessage + "HelpFile: " + pkgError.HelpFile + "\n";

sErrorMessage = sErrorMessage + "IDOfInterfaceWithError: " + pkgError.IDOfInterfaceWithError + "\n";

sErrorMessage = sErrorMessage + "Source: " + pkgError.Source + "\n";

sErrorMessage = sErrorMessage + "Subcomponent: " + pkgError.SubComponent + "\n";

sErrorMessage = sErrorMessage + "Timestamp: " + pkgError.TimeStamp + "\n";

sErrorMessage = sErrorMessage + "ErrorCode: " + pkgError.ErrorCode;

}

MessageBox.Show("The DTS package was not built successfully because of the following error(s):\n\n" + sErrorMessage, "Package Builder", MessageBoxButtons.OK, MessageBoxIcon.Information);

return false;

}

// return a successful result

return true;

}

So the OLE-DB Destination is not happy and I cannot see anything obvious. A better way to debug this would be to just add a Save method before validation to save your package to disk. You can then open it in Visual Studio/BIDS, and enjoy the full GUI experience to help find the problem. I've found this method very useful for just checking packages when building programmatically.

|||

I have inserted code to save the package just before the validation but it throws an exception. And I don't find the help in MSDN very useful!! I want to save the package in the folder C:\LPFMigrate and call it Package.dtsx. The code is as follows:

oApp = new Microsoft.SqlServer.Dts.Runtime.Application();

oApp.SaveToDtsServer(oPackage, null, @."C:\LPFMigrate\Package", "MARS");

Any idea why an exception is being thrown? The exception message is:

The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

Thursday, February 16, 2012

<asp:SqlDataSource> need a look over to see If I am writing this correctly.

This is a subset question of one of my other threads, the gist is while using forms authentication, I am trying to enter additional information into another table on the same db as the aspnet_membership tables. I think I need an <asp:SqlDataSource> to do this because it is about the only thing left I haven't tried to get this code to work so any help is appreciated. Environment: sql server 2000, windows server 2003, asp.net 2.0, vb, no GUI

<ASP:SqlDataSource id="addedInfo" ConnectionString="<%$ ConnectionStrings:SqlServerConnection %>" InsertCommand="INSERT INTO addInfo(username,email,company,firstname,lastname,phone) VALUES (@.username,@.email,@.company,@.firstname,@.lastname,@.phone)" runat="server" />

looking over some of my books and online it says in the connectionStrings that it is supposed to be the database name that goes next to the : but when I try that I get an error that it is looking for the name of the connection string, so I enter the name of the connection string (as above) and nothing happens, which is basically the ongoing event with this whole problem, the form fields (username, email, password) that go into the aspnet_membership tables just fine, I don't have any problems with those, it is getting the additional information into another table that has been stalling me the whole time.

So does this sqldatasource look right? Any help is appreciated.

this is the full page of register.aspx

<%@. Page Explicit="true" debug="true" language="vb" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
<%@. Import Namespace="System.Data.Mail" %>
<%@. Import Namespace="System.Net.Mail" %>

<script runat="server">

Public Sub CreateUser_OnClick(sender As Object, args As EventArgs)
Dim result As MembershipCreateStatus
Try
' Create new user.

Dim newUser As MembershipUser
If Membership.RequiresQuestionAndAnswer Then
newUser = Membership.CreateUser(UsernameTextbox.Text,PasswordTextbox.Text,EmailTextbox.Text,PasswordQuestionTextbox.Text, PasswordAnswerTextbox.Text,false,result)
Else
newUser = Membership.CreateUser(UsernameTextbox.Text,PasswordTextbox.Text,EmailTextbox.Text)
End If


Response.Redirect("login.aspx")

Catch e As MembershipCreateUserException
Msg.Text = GetErrorMessage(e.StatusCode)
Catch e As HttpException
Msg.Text = e.Message
End Try
End Sub

Public Function GetErrorMessage(status As MembershipCreateStatus) As String

Select Case status
Case MembershipCreateStatus.DuplicateUserName
Return "Username already exists. Please enter a different user name."

Case MembershipCreateStatus.DuplicateEmail
Return "A username for that e-mail address already exists. Please enter a different e-mail address."

Case MembershipCreateStatus.InvalidPassword
Return "The password provided is invalid. Please enter a valid password value."

Case MembershipCreateStatus.InvalidEmail
Return "The e-mail address provided is invalid. Please check the value and try again."

Case MembershipCreateStatus.InvalidAnswer
Return "The password retrieval answer provided is invalid. Please check the value and try again."

Case MembershipCreateStatus.InvalidQuestion
Return "The password retrieval question provided is invalid. Please check the value and try again."

Case MembershipCreateStatus.InvalidUserName
Return "The user name provided is invalid. Please check the value and try again."

Case MembershipCreateStatus.ProviderError
Return "The authentication provider Returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator."

Case MembershipCreateStatus.UserRejected
Return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator."

Case Else
Return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator."
End Select
End Function

</script>

<form runat="server" id="form1">
<h3>Create New User</h3>

<asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR>

<table CellPadding="3" border="0">
<tr>
<td><span class="style5">Username:</span></td>
<td><asp:Textbox id="UsernameTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
ControlToValidate="UserNameTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Password:</span></td>
<td><asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /></td>
<td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server"
ControlToValidate="PasswordTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Confirm Password:</span></td>
<td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td>
<td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server"
ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" />
<asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server"
ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
Display="Static" ControlToCompare="PasswordTextBox"
ErrorMessage="Confirm password must match password." /> </td>
</tr>
<tr>
<td><span class="style5">Email Address:</span></td>
<td><asp:Textbox id="EmailTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
ControlToValidate="EmailTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>


<% If Membership.RequiresQuestionAndAnswer Then %>

<tr>
<td>Password Question:</td>
<td><asp:Textbox id="PasswordQuestionTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PasswordQuestionRequiredValidator" runat="server"
ControlToValidate="PasswordQuestionTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td>Password Answer:</td>
<td><asp:Textbox id="PasswordAnswerTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PasswordAnswerRequiredValidator" runat="server"
ControlToValidate="PasswordAnswerTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<% End If %>
</table>
<!-- so much trouble below! -->
<table cellpadding="3" cellspacing="0">
<tr>
<td width="122"><span class="style5">Company:</span>
</td>
<td width="144"><asp:Textbox id="CompanyTextbox" runat="server" /></td>
<td width="387"><asp:RequiredFieldValidator id="CompanyValidator" runat="server" ControlToValidate="CompanyTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">First Name:</span></td>
<td><asp:Textbox id="FirstNameTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="FirstNameValidator" runat="server" ControlToValidate="FirstNameTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Last Name:</span> </td>
<td><asp:Textbox id="LastNameTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="LastNameValidator" runat="server" ControlToValidate="LastNameTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Phone Number:</span> </td>
<td><asp:Textbox id="PhoneTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PhoneValidator" runat="server" ControlToValidate="PhoneTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" />
<ASP:SqlDataSource id="addedInfo" ConnectionString="<%$ ConnectionStrings:SqlElectron %>" InsertCommand="INSERT INTO addInfo(username,email,company,firstname,lastname,phone) VALUES (UserNameTextbox,EmailTextbox,CompanyTextbox,FirstNameTextbox,LastNameTextbox,PhoneTextbox)" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="CreateUserButton" CssClass="style5" Text="Create User" OnClick="CreateUser_OnClick" runat="server" /></td>
</tr>
</table>
</form>

From some tests right now the entire code is just being ignored. I've tried to break this by intentionally adding fields that don't exist into the add so that it would return (I forget what it is precisily called) the error where it says that the fields being entered do not match the database. As always any help is appreciated.

|||

For a minute there thought I actually figured out what I didn't do, I didn't add the DataSourceID to the textboxes, so I added it and nothing happens still the same problem :( So below is the current version of the code:

<form runat="server" id="form1">
<h3>Create New User</h3>

<asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR>

<table CellPadding="3" border="0">
<tr>
<td><span class="style5">Username:</span></td>
<td><asp:Textbox id="UsernameTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
ControlToValidate="UserNameTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Password:</span></td>
<td><asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /></td>
<td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server"
ControlToValidate="PasswordTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Confirm Password:</span></td>
<td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td>
<td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server"
ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" />
<asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server"
ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
Display="Static" ControlToCompare="PasswordTextBox"
ErrorMessage="Confirm password must match password." /> </td>
</tr>
<tr>
<td><span class="style5">Email Address:</span></td>
<td><asp:Textbox id="EmailTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
ControlToValidate="EmailTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>


<% If Membership.RequiresQuestionAndAnswer Then %>

<tr>
<td>Password Question:</td>
<td><asp:Textbox id="PasswordQuestionTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PasswordQuestionRequiredValidator" runat="server"
ControlToValidate="PasswordQuestionTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td>Password Answer:</td>
<td><asp:Textbox id="PasswordAnswerTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PasswordAnswerRequiredValidator" runat="server"
ControlToValidate="PasswordAnswerTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<% End If %>
</table>
<!-- so much trouble below! -->
<table cellpadding="3" cellspacing="0">
<tr>
<td width="122"><span class="style5">Company:</span>
</td>
<td width="144"><asp:Textbox id="CompanyTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td width="387"><asp:RequiredFieldValidator id="CompanyValidator" runat="server" ControlToValidate="CompanyTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">First Name:</span></td>
<td><asp:Textbox id="FirstNameTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="FirstNameValidator" runat="server" ControlToValidate="FirstNameTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Last Name:</span> </td>
<td><asp:Textbox id="LastNameTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="LastNameValidator" runat="server" ControlToValidate="LastNameTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Phone Number:</span> </td>
<td><asp:Textbox id="PhoneTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="PhoneValidator" runat="server" ControlToValidate="PhoneTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" />
<asp:SqlDataSource id="addedInfo" ConnectionString="<%$ ConnectionStrings:SqlElectron %>" InsertCommand="INSERT INTO addInfo(username,email,company,firstname,lastname,phone) VALUES (UserNameTextbox,EmailTextbox,CompanyTextbox,FirstNameTextbox,LastNameTextbox,PhoneTextbox)" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="CreateUserButton" CssClass="style5" Text="Create User" OnClick="CreateUser_OnClick" runat="server" /></td>
</tr>
</table>
</form>

any help is appreciated. I've been working on this problem now for the better part of two weeks, and I am simply out of ideas as to the problem.

|||

For a minute there thought I actually figured out what I didn't do, I didn't add the DataSourceID to the textboxes, so I added it and nothing happens still the same problem :( So below is the current version of the code:

<form runat="server" id="form1">
<h3>Create New User</h3>

<asp:Label id="Msg" ForeColor="maroon" runat="server" /><BR>

<table CellPadding="3" border="0">
<tr>
<td><span class="style5">Username:</span></td>
<td><asp:Textbox id="UsernameTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="UsernameRequiredValidator" runat="server"
ControlToValidate="UserNameTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Password:</span></td>
<td><asp:Textbox id="PasswordTextbox" runat="server" TextMode="Password" /></td>
<td><asp:RequiredFieldValidator id="PasswordRequiredValidator" runat="server"
ControlToValidate="PasswordTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Confirm Password:</span></td>
<td><asp:Textbox id="PasswordConfirmTextbox" runat="server" TextMode="Password" /></td>
<td><asp:RequiredFieldValidator id="PasswordConfirmRequiredValidator" runat="server"
ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" />
<asp:CompareValidator id="PasswordConfirmCompareValidator" runat="server"
ControlToValidate="PasswordConfirmTextbox" ForeColor="red"
Display="Static" ControlToCompare="PasswordTextBox"
ErrorMessage="Confirm password must match password." /> </td>
</tr>
<tr>
<td><span class="style5">Email Address:</span></td>
<td><asp:Textbox id="EmailTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="EmailRequiredValidator" runat="server"
ControlToValidate="EmailTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>


<% If Membership.RequiresQuestionAndAnswer Then %>

<tr>
<td>Password Question:</td>
<td><asp:Textbox id="PasswordQuestionTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PasswordQuestionRequiredValidator" runat="server"
ControlToValidate="PasswordQuestionTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td>Password Answer:</td>
<td><asp:Textbox id="PasswordAnswerTextbox" runat="server" /></td>
<td><asp:RequiredFieldValidator id="PasswordAnswerRequiredValidator" runat="server"
ControlToValidate="PasswordAnswerTextbox" ForeColor="red"
Display="Static" ErrorMessage="Required" /></td>
</tr>
<% End If %>
</table>
<!-- so much trouble below! -->
<table cellpadding="3" cellspacing="0">
<tr>
<td width="122"><span class="style5">Company:</span>
</td>
<td width="144"><asp:Textbox id="CompanyTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td width="387"><asp:RequiredFieldValidator id="CompanyValidator" runat="server" ControlToValidate="CompanyTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">First Name:</span></td>
<td><asp:Textbox id="FirstNameTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="FirstNameValidator" runat="server" ControlToValidate="FirstNameTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Last Name:</span> </td>
<td><asp:Textbox id="LastNameTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="LastNameValidator" runat="server" ControlToValidate="LastNameTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" /></td>
</tr>
<tr>
<td><span class="style5">Phone Number:</span> </td>
<td><asp:Textbox id="PhoneTextbox" runat="server" DataSourceID="addedInfo" /></td>
<td><asp:RequiredFieldValidator id="PhoneValidator" runat="server" ControlToValidate="PhoneTextbox" ForeColor="red" Display="Static" ErrorMessage="Required" />
<asp:SqlDataSource id="addedInfo" ConnectionString="<%$ ConnectionStrings:SqlElectron %>" InsertCommand="INSERT INTO addInfo(username,email,company,firstname,lastname,phone) VALUES (UserNameTextbox,EmailTextbox,CompanyTextbox,FirstNameTextbox,LastNameTextbox,PhoneTextbox)" runat="server" />
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="CreateUserButton" CssClass="style5" Text="Create User" OnClick="CreateUser_OnClick" runat="server" /></td>
</tr>
</table>
</form>

any help is appreciated. I've been working on this problem now for the better part of two weeks, and I am simply out of ideas as to the problem.

|||

Public Sub CreateUser_OnClick(sender As Object, args As EventArgs)
Dim result As MembershipCreateStatus
Try
' Create new user.

Dim newUser As MembershipUser
If Membership.RequiresQuestionAndAnswer Then
newUser = Membership.CreateUser(UsernameTextbox.Text,PasswordTextbox.Text,EmailTextbox.Text,PasswordQuestionTextbox.Text, PasswordAnswerTextbox.Text,false,result)
Else
newUser = Membership.CreateUser(UsernameTextbox.Text,PasswordTextbox.Text,EmailTextbox.Text)
End If

dim conn as new sqlconnection(system.configuration.configurationmanager.connectionstrings("SqlElectron").connectionstring)

dim cmd as new sqlcommand("INSERT INTO addInfo(username,email,company,firstname,lastname,phone) VALUES (@.UserNameTextbox,@.EmailTextbox,@.CompanyTextbox,@.FirstNameTextbox,@.LastNameTextbox,@.PhoneTextbox)",conn)

cmd.parameters.add("@.UserNameTextbox",varchar).value=UsernameTextbox.Text

cmd.parameters.add("@.EmailTextbox",varchar).value=EmailTextbox.Text

{Add rest of fields here}

conn.open

cmd.executenonquery

conn.close

Response.Redirect("login.aspx")

Catch e As MembershipCreateUserException
Msg.Text = GetErrorMessage(e.StatusCode)
Catch e As HttpException
Msg.Text = e.Message
End Try
End Sub

|||

First thanks for the help moley

second the code errors out with two errors first it needs varchar set to a value and the connection string it saysSystem.NullReferenceException: Object reference not set to an instance of an object.

I'm working on a variant of what you posted and Ill post it as soon as I get it done with whether it works or not.

|||yep it gives me the beginning of the findcontrol loop logic error that I have in one of my other threadshttp://forums.asp.net/2/1381460/ShowThread.aspx . basically

No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.ArgumentException: No mapping exists from object type System.Web.UI.WebControls.TextBox to a known managed provider native type.

Source Error:

Line 37: Line 38: SQLConn.Open()Line 39: cmd.ExecuteNonQueryLine 40: SQLConn.CloseLine 41:


Source File:C:\Inetpub\wwwroot\login\register.aspx Line:39

It can never find the value of the textboxes because the textboxes get wiped out in the process of the membership being made, If I try to put this type of code before the membership stuff it will not find anything, If I use findcontrol() to try and extract the value it will return with nothing and thus I return to my two week+ nightmare of trying to get this to work. I assumed since I needed to trap the info that I could use the <asp:SqlDataSource to do that and then send it's insert seperatly but I guess that doesn't work.

For those forum members that have a custom registration page (basically something that adds more fields than what is in the CreateUserWizard) how do you enter those fields? I honest to gawd don't know what I am missing but basically I have tried every code example I could come across, I've tried everything other forumers have tried, I just have no idea what I am missing or not doing? I can enter the basic forms data fine (username, email, password) that enters the aspnet_membership tabels fine but I can get nothing into the addInfo table that I have in the same database. Any help is appreciated and thanks to everyone who has been helping me.

|||

The big error:

You forgot to supply .Text when assigning the value to one of the parameters.

First error:

Change:

cmd.parameters.add("@.UserNameTextbox",varchar).value=UsernameTextbox.Text

to:

cmd.Parameters.Add("@.UserNameTextbox",sqldbtype.varchar).Value=UsernameTextbox.Text

varchar isn't a variable, it's a value from the system.data.sqldbtype enumeration.

--

Second Error:

Please post your web.config file (Please make sure you remove any passwords by using XXXXXXXX instead of the real password before posting).

|||

<configuration>
<appSettings>
<add key="ConnectionString" value="DataSource=mew@.mew.com;UID=bark;pwd=xxxxxxxxx" />
<add key="ConnectionString" value="Server=xxx.xxx.xxx.xxx;database=customerlogin;UID=yyyyyyyy;pwd=xxxxxxxx;Trusted_Connection=True" />
</appSettings>
<connectionStrings>
<add name="SqlServerConnection" connectionString="Server=xxx.xxx.xxx.xxx;database=customerlogin;UID=yyyyyyyy;pwd=xxxxxxxx;Trusted_Connection=True" />
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=xxx.xxx.xxx.xxx;Integrated Security=SSPI;Initial Catalog=customerlogin;UID=yyyyyyyyy;pwd=xxxxxxxxx;Trusted_Connection=True" />
</connectionStrings>
<location path="lock">
<system.web>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
</system.web>
<system.web>
<authentication mode="Forms">
<forms cookieless="AutoDetect" defaultUrl="~\lock\library.aspx" loginUrl="../login.aspx" name=".ASPXAUTH" />
</authentication>
</system.web>
<system.web>
<membership defaultProvider="MyProvider">
<providers>
<add name="MyProvider" type="System.Web.Security.SqlMembershipProvider" passwordFormat="Clear" connectionStringName="LocalSqlServer" requiresQuestionAndAnswer="false" />
</providers>
</membership>
</system.web>
<system.web>
<profile enabled="true">
<properties>
<add name="company" type="String" />
<add name="firstname" type="String"/>
<add name="lastname" type="String"/>
<add name="phone" type="String" />
</properties>
</profile>
</system.web>
</location>
</configuration>

The highlighted UID's are the same and thus consequently the passwords are the same. I removed the SqlElectron from the previous examples since making a second account didn't help the matter and have gone back to alternating between the SqlServerConnection and LocalSqlServer connections depending on what variable I am testing. Thanks for the help Motley.

|||

Here:

PrivateFunction SuperFindControl(ByVal ctrlAsString,OptionalByVal basectrlAs Control =Nothing)As Control

If basectrlIsNothingThen

basectrl = Page

EndIf

If basectrl.Controls.Count > 0Then

ForEach cAs ControlIn basectrl.Controls

If c.IDIsNotNothingAndAlso c.ID.ToLower = ctrl.ToLowerThen

Return c

Else

If c.Controls.Count > 0Then

Dim c2As Control = SuperFindControl(ctrl, c)

IfNot c2IsNothingThen

Return c2

EndIf

EndIf

EndIf

Next

EndIf

ReturnNothing

EndFunction

Now you can reference your control as SuperFindControl("txtCompanyTextBox") anywhere in your code -- but it will only return the first one it finds with that id if you have more than one.

|||

Motley:

The big error:

You forgot to supply .Text when assigning the value to one of the parameters.

First error:

Change:

cmd.parameters.add("@.UserNameTextbox",varchar).value=UsernameTextbox.Text

to:

cmd.Parameters.Add("@.UserNameTextbox",sqldbtype.varchar).Value=UsernameTextbox.Text

varchar isn't a variable, it's a value from the system.data.sqldbtype enumeration.

--

Second Error:

Please post your web.config file (Please make sure you remove any passwords by using XXXXXXXX instead of the real password before posting).

W00T it works! The highlighted ontop of whatever other changes I've made(ill have to break the page to find out what actually did it) have worked, I get the additional info in the new table and everything works well, Thanks a lot Motley you have been a lifesaver, and more than likely helped me keep my job. I would give you a hug but we dont know each other well enough lol, so

/e handshake

Thanks a lot.

|||

Now only one problem left to fix, but now I can close three threads that were all related to each other.

Login.aspx I'm looking at you next!

Thanks again Motley.

|||

Given your web.config file, the connection should be:

dim conn as new sqlconnection(system.configuration.configurationmanager.connectionstrings("LocalSqlServer").connectionstring)