Showing posts with label connecting. Show all posts
Showing posts with label connecting. Show all posts

Wednesday, March 28, 2012

Trouble connecting to AS/400 with ASP.NET

Hello,

I am writing an ASP.NET application and trying to connect to an as400
using an ADODB connection. I recently completed a Windows application
that connects to the 400. My code works in the Windows world, so
theoretically, it should work for the ASP application as well. But it
doesn't. I keep getting the error CWBSY1006 - User ID is Invalid. I'm
using my Windows login information to automatically log into the 400,
so a userid and password is not required. It does work, however, if I
hard code my userid and password into the connection string. The
only problem with that is that the users need to log in with their
information for security purposes. Here is my code. Any ideas would
be greatly appreciated.

Thanks,
Amaryllis

AS400.Define("MyAS400")
AS400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceDa taQueues)
conn400 = New ADODB.Connection
conn400.ConnectionString = "Provider=IBMDA400.DataSource.1;" & _
"Data source=MyAS400"
conn400.Open()That is because ASP.NET runs under the ASPNET account. It does not run
under you. So of course, the ASPNET account does not have integrated
security access to your database.

You neither need to give that account rights to the database, or use a
username/password to log in.

"Amaryllis" <amy_hankins@.swn-dot-com.no-spam.invalid> wrote in message
news:410fe1bf$1_5@.Usenet.com...
> Hello,
> I am writing an ASP.NET application and trying to connect to an as400
> using an ADODB connection. I recently completed a Windows application
> that connects to the 400. My code works in the Windows world, so
> theoretically, it should work for the ASP application as well. But it
> doesn't. I keep getting the error CWBSY1006 - User ID is Invalid. I'm
> using my Windows login information to automatically log into the 400,
> so a userid and password is not required. It does work, however, if I
> hard code my userid and password into the connection string. The
> only problem with that is that the users need to log in with their
> information for security purposes. Here is my code. Any ideas would
> be greatly appreciated.
> Thanks,
> Amaryllis
> AS400.Define("MyAS400")
> AS400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceDa taQueues)
> conn400 = New ADODB.Connection
> conn400.ConnectionString = "Provider=IBMDA400.DataSource.1;" & _
> "Data source=MyAS400"
> conn400.Open()
I agree, but when you add <impersonate=TRUE /> to the web.config
file, it should pick up your information and use it rather than the
ASPNET account information. I've always been able to connect to SQL
Server using that approach. I'm just not sure what is different
about DB2 on the AS/400.

Amaryllis

Trouble connecting to an SQL database in C#

Hi guys,

I'm using Visual Web Developer and I've made a GridView and I want to learn how to display information in it (or any other databound control) rather than doing it through the asp source code. I'm using the following code so far, and although I've probably made some errors in it I think there is a problem connecting to the database remotely as I get the following error on the "myConnection.Open()" line.

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I tried following the instructions here http://www.datamasker.com/SSE2005_NetworkCfg.htm but didn't have much luck as I don't seem to have the interface shown in the screen prints.

My code so far is

SqlConnection myConnection = new SqlConnection("Server=local;database=WroxUnited");
SqlCommand myCommand = new SqlCommand("SELECT * FROM [Fixtures]", myConnection);

myConnection.Open();

GridView1.DataSource = myCommand.ExecuteReader();
GridView1.DataBind();

myConnection.Close();

Thanks in advance.You specified a server (Local) and a database (WroxUnited) ... just so that we're on the same page, that isn't a remote DB... it's local on your PC.

But the problem is probably because you didn't specify an authentication method... do you intend to use integrated security (using WIndows Authentication) or to use SQL Server Authentication? IF you want integrated securtity then you need to add "Integrated Security=SSPI;" to the connection string otherwise add "Integrated Security=False;User ID=XXXXXX;Password=YYYYYYYY;"

-tg
You can make use of the idea in this code:

SqlConnection sc1 = new SqlConnectionConfigurationManager.ConnectionStrings ["CompanyConnectionString"].ToString ());
SqlDataAdapter sa1 = new SqlDataAdapter();
sc1.Open();
string c = "Select Name , Postion_Name from Employee join Postion on Postion_Num=Postion_ID";
SqlCommand sqc1 = new SqlCommand(c,sc1);
DataSet ds = new DataSet();
sa1.SelectCommand = sqc1;
sa1.Fill(ds);
GridView1.DataSource = ds;
What's annoying is there seems to be so many different ways to go about it, and as I'm just beginning to learn .NET it's all a bit confusing. I'm sure I'll get it eventually but I'm worried I may have already got it but something's not set up correctly to work. However if I do it through ASP source code using a ConnectionString=<%$ConnectionStrings=WroxUnited%> for example then it does work so I suppose it's unlikely to be a problem with the SQL Server set-up.

Just to test that it does actually work would someone be kind enough to post here the smallest amount of code necessary to display data from a database called WroxUnited.mdf stored in the C:, in a gridview called GridView1? Or if it's easier to use another data control then let me know and I'll do it that way.

Thanks for all the help!

Trouble Connecting

I'm developing locally on my computer
Installed on My computer:
OS - XP Professional
IIS
1.1.Net Framework
MSDE
WebMatrix
Macromedia DreamWeaver MX



Having a Problem Connecting to my SQL Database using the following:

void Button_Click(object sender, EventArgs e)
{
SqlConnection conNewstore;
string strInsert;
SqlCommand cmdInsert;

conNewstore = new SqlConnection( "Server=(local);Integrated Security=SSPI;database=Newstore" );
strInsert = "Insert OrderPayment ( FullName, OrderID, CustomerID ) Values (@dotnet.itags.org.FullName, @dotnet.itags.org.OrderID, @dotnet.itags.org.CustomerID )";
cmdInsert = new SqlCommand( strInsert, conNewstore );
cmdInsert.Parameters.Add( "@dotnet.itags.org.FullName", FullName.Text );
cmdInsert.Parameters.Add( "@dotnet.itags.org.OrderID", OrderID.Text );
cmdInsert.Parameters.Add( "@dotnet.itags.org.CustomerID", CustomerID.Text );
conNewstore.Open();
cmdInsert.ExecuteNonQuery();
conNewstore.Close();
}



Please Note: if I change the connection string to this
conNewstore = new SqlConnection( "Server=(local);USER ID=sa;Password=Mypassword;database=Newstore" );
It works fine.

But if I use this connection:conNewstore = new SqlConnection( "Server=(local);Integrated Security=SSPI;database=Newstore" ); It does not work

Any Help would be Great!! Thank You!





Here is the error message I receive

Server Error in '/NewStoreCS' Application.

Login failed for user 'MYNAME\ASPNET'.
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.Data.SqlClient.SqlException: Login failed for user 'MYNAME\ASPNET'.

Source Error:

Line 14: cmdInsert = new SqlCommand( strInsert, conNewstore );
Line 15: cmdInsert.Parameters.Add( "@dotnet.itags.org.FullName", txtFullName.Text );
Line 16: conNewstore.Open();
Line 17: cmdInsert.ExecuteNonQuery();
Line 18: conNewstore.Close();

Source File: C:\Inetpub\wwwroot\NewStoreCS\InsertPage.aspx Line: 16

Stack Trace:

[SqlException: Login failed for user 'MYNAME\ASPNET'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +474
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
ASP.InsertPage_aspx.Button_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\NewSToreCS\InsertPage.aspx:16
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277

Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573


Since you are using "Integrated Security=SSPI", the login credentials for the ASPNET user are used to log into the SQL Server. If you want to use this integrated security you need to create a MYNAME\ASPNET account in SQL Server and give it the proper permissions.
Thank you.

Do you know where I can read (find info) on how to do this? Thanks again.

Trouble connecting to AS/400 with ASP.NET

Hello,
I am writing an ASP.NET application and trying to connect to an as400
using an ADODB connection. I recently completed a Windows application
that connects to the 400. My code works in the Windows world, so
theoretically, it should work for the ASP application as well. But it
doesn't. I keep getting the error CWBSY1006 - User ID is Invalid. I'm
using my Windows login information to automatically log into the 400,
so a userid and password is not required. It does work, however, if I
hard code my userid and password into the connection string. The
only problem with that is that the users need to log in with their
information for security purposes. Here is my code. Any ideas would
be greatly appreciated.
Thanks,
Amaryllis
AS400.Define("MyAS400")
AS400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceDataQueues)
conn400 = New ADODB.Connection
conn400.ConnectionString = "Provider=IBMDA400.DataSource.1;" & _
"Data source=MyAS400"
conn400.Open()That is because ASP.NET runs under the ASPNET account. It does not run
under you. So of course, the ASPNET account does not have integrated
security access to your database.
You neither need to give that account rights to the database, or use a
username/password to log in.
"Amaryllis" <amy_hankins@.swn-dot-com.no-spam.invalid> wrote in message
news:410fe1bf$1_5@.mcse.ms...
> Hello,
> I am writing an ASP.NET application and trying to connect to an as400
> using an ADODB connection. I recently completed a Windows application
> that connects to the 400. My code works in the Windows world, so
> theoretically, it should work for the ASP application as well. But it
> doesn't. I keep getting the error CWBSY1006 - User ID is Invalid. I'm
> using my Windows login information to automatically log into the 400,
> so a userid and password is not required. It does work, however, if I
> hard code my userid and password into the connection string. The
> only problem with that is that the users need to log in with their
> information for security purposes. Here is my code. Any ideas would
> be greatly appreciated.
> Thanks,
> Amaryllis
> AS400.Define("MyAS400")
> AS400.Connect(cwbx.cwbcoServiceEnum.cwbcoServiceDataQueues)
> conn400 = New ADODB.Connection
> conn400.ConnectionString = "Provider=IBMDA400.DataSource.1;" & _
> "Data source=MyAS400"
> conn400.Open()
>
I agree, but when you add <impersonate=TRUE /> to the web.config
file, it should pick up your information and use it rather than the
ASPNET account information. I've always been able to connect to SQL
Server using that approach. I'm just not sure what is different
about DB2 on the AS/400.
Amaryllis

trouble connecting to remote SQL server for authentication

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows
<?xml version="1.0" encoding="utf-8"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword
" />
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<membership>
<providers>
<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
</system.web>
</configuration>
and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?
----
--Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.
NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
****************************************
*********
Think outside of the box!
****************************************
*********
<brian.newman@.wpafb.af.mil> wrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegroups.com...
> I've got an app which provides data based on the user who is logged in.
> So, I need the user data to be on the same db server as the other
> data. I'm trying to do this using the membership API. I've set up the
> tables and sprocs and so forth using the aspnet_regsql.exe (though, for
> some reason, I had to do it using windows authentication rather than
> using a SQL server account). I've modified the web.config file as
> follows
> <?xml version="1.0" encoding="utf-8"?>
> <configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <connectionStrings>
> <add name="SLAR-con" connectionString="Data
> Source=mySQLserver;Initial Catalog=SLAR;User
> Id=mydomain\myuserid;Password=mypassword
" />
> </connectionStrings>
> <system.web>
> <roleManager enabled="true" />
> <authentication mode="Forms" />
> <membership>
> <providers>
> <add connectionStringName="SLAR-con"
> applicationName="SLAR" minRequiredPasswordLength="5"
> minRequiredNonalphanumericCharacters="0"
> name="CustomizedProvider"
> type="System.Web.Security.SqlMembershipProvider" />
> </providers>
> </membership>
>
> </system.web>
> </configuration>
> and I've tested the login and it seems to be working. However, when I
> go into the database on the SQL server to look at the user I created,
> the user authentication tables are all empty. The data isn't being
> stored on the SQL server where I want it to be (I'm assuming it is
> being stored in a SQL Server express database on the local machine).
> How do I get the data to be stored in the remote SQL server?
>
> ----
--
>
Cowboy (Gregory A. Beamer) wrote:
> Check both databases and make sure it is not pointiong locally. As long as
> machine name is correct, you should be on the other server.
> NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You als
o
> have to have proper transports set up, as some versions install without
> TCP/IP or named pipes on.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> http://gregorybeamer.spaces.live.com
> ****************************************
*********
> Think outside of the box!
> ****************************************
*********
> <brian.newman@.wpafb.af.mil> wrote in message
> news:1161862621.467371.69570@.i3g2000cwc.googlegroups.com...
It is being stored locally (local to the machine on which I'm doing the
development), but I'm unclear on how to point it to the SQL server db.
I thought the edits shown in the top post I made to the web.config file
would handle that, but they don't. The SQL server db is SQL Server
2000.
By the way, thanks for the assist. I posted on Microsoft asp.net forum
and got 20 views, but no assist and got nothing from 4guysfromrolla.

trouble connecting to remote SQL server for authentication

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows

<?xml version="1.0" encoding="utf-8"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />

</connectionStrings>

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms" />

<membership>

<providers>

<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"

type="System.Web.Security.SqlMembershipProvider" />

</providers>

</membership>

</system.web>

</configuration>

and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?

------------------------Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.

NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
*************************************************
Think outside of the box!
*************************************************
<brian.newman@.wpafb.af.milwrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows
>
<?xml version="1.0" encoding="utf-8"?>
>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>
<connectionStrings>
>
<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />
>
</connectionStrings>
>
<system.web>
>
<roleManager enabled="true" />
>
<authentication mode="Forms" />
>
<membership>
>
<providers>
>
<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"
>
minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"
>
type="System.Web.Security.SqlMembershipProvider" />
>
</providers>
>
</membership>
>
>
>
</system.web>
>
</configuration>
>
and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?
>
>
------------------------
>


Cowboy (Gregory A. Beamer) wrote:

Quote:

Originally Posted by

Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.
>
NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
>
*************************************************
Think outside of the box!
*************************************************
<brian.newman@.wpafb.af.milwrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows

<?xml version="1.0" encoding="utf-8"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />

</connectionStrings>

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms" />

<membership>

<providers>

<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"

type="System.Web.Security.SqlMembershipProvider" />

</providers>

</membership>

</system.web>

</configuration>

and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?

------------------------


It is being stored locally (local to the machine on which I'm doing the
development), but I'm unclear on how to point it to the SQL server db.
I thought the edits shown in the top post I made to the web.config file
would handle that, but they don't. The SQL server db is SQL Server
2000.
By the way, thanks for the assist. I posted on Microsoft asp.net forum
and got 20 views, but no assist and got nothing from 4guysfromrolla.