Showing posts with label aspnet. Show all posts
Showing posts with label aspnet. Show all posts

Sunday, March 25, 2012

Connecting to SQL in ASP.net 20

I have a database that is currently connected and working properly in My SQL Server Management Studio. The problem I am havings is when I open My ASP.net 20 and Look in my Server Solutions I can not find the database to connect to it . It seems to be trying to use SLQ Express and not my SLQ Server Management Studio. How do I get my database to connect in my application? All I can see from within the Server solutions in ASP is the database .bak file which is the backup of the database. I thank you in advance.

Are you saying that, when you are trying to connect to the Server in the Server Explorer, that the server does not show up in the list?

Is the server 2000 or 2005 or.....?

|||Yes and no . I think I dono have my SQL Server Manager Studio (Dev ed) is not set as my primary and the SQL Express is . I think I need to configure my SQL Server Manager Studioas primary but am not sure how to do this. and help would be get.|||My question was concerning inside Visual Web Developer - the Server Explorer window|||Inside the designer in the server explorer the sever shows up ok but the database does not|||Inside the designer in the server explorer the sever shows up ok but the database does not

connecting to SQL db in an asp.net page

Ok, I'm an experienced asp developer switching to asp.net.

I've used the "Quickstart Tutorials" (http://www.asp.net/Tools/redir.aspx?path=quickstart) and have gotten started that way and built a few things based on that, but they only show XML connection info. Now I need to switch to SQL so I can connect to MS SQL Server for some stored procedures.

Anyone have suggestions?

(I've dug through some articles on msdn, etc, but I've only found so far theory and not code. And let me tell 'ya, I'm big on learning about code from code.)

If this helps, the specific tasks I'm trying to do are:
Have user select a static value from a drop down list, enter a word in a text box, and submit the form (so far so good), which connects to the db and returns the datagrid filled with results (the part I don't have). I already have my sp, just can't connect to it and get results back into the page.The Tutorials on this site have an example of doing just that. Check outPerforming a Parameterized Select

Sound like you have all of the pieces you need, you just need to stitch them together. Viewing the source code of that example should help you do just that. Post back if you are having trouble implementing it.

Terri|||I receive this error:

Server Error in '/Test1' Application.
------------------------

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested Url: /Test1/VB/datagrid2.aspx|||The problem is probably with the SqlConnection -- specifically, it is trying to read the connection string out of the web.config file. This is a good practice. But, let's try to get the sample running for you first.

Instead of this line:

MyConnection = New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("PubsString"))

Try this line (assuming you are using a local SQL Server with Windows authentication)
MyConnection = New SqlClient.SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")

Terri|||Ok, I'm looking at these various example ways to set up and connect to dbs.

I have a local sql server running on my machine.
I can use the sa account.
I have databases, sps, and tables already on it.

I've tried looking at the examples and changing to fit, but either I'm missing something or I've put info in the wrong place.

hum.|||YAY YAY YAY!!!

Thank you! I changed your line:
MyConnection = New SqlClient.SqlConnection("server=(local);database=pubs;Trusted_Connection=yes")

To:
MyConnection = New SqlClient.SqlConnection("server=(local);database=mydbname;uid=sa;pwd=sa;")

and it works in the datagrid2.aspx sample file! 8)

Whew!

Ok, now time to get this working in my files...

Thanks again!

Monday, March 19, 2012

Connecting to MS SQL server 2000 from the different domains using asp.net

Hi,

My problem is somewhat like this that, i want to connect my all applications (developed in asp.net) to one database. In other words i want to make a centralised database that can be accessible from the application running at the different domains. When i did so by using the same username, password, database and server...i recieve an error that,"connection cannot be establised".

If any body have the solution for this problem. then please do write the "connection string" for me that can be efficiantly used on the applications running on differnt domains.

Thanks and Regards,

Steve Dcosta

Considering the domains trust each other and that you have the proper rights for accessing the database server from each of the different domains you can try the following connectionString replacing the correct values for the variables:

data source=putIPHereIncaseNameResolutionFails;user id=user;password=yourPassword;initial catalog=databaseName;persist security info=True

Sunday, March 11, 2012

Connecting to DB Stored Proc with asp.net

I am used to using asp and i am trying to connect to a db and bring back a recordset from a stored procedure in asp.net, but I am getting the following error;

Server Error in '/' Application.

Object variable or With block variable not set.

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.NullReferenceException: Object variable or With block variable not set.
Source Error:

Line 58: Line 59: qry = "AWS_RPT_WEB_MAGSUBSSTATS_PROC "Line 60: rs = dbConn.Execute(qry)Line 61: %>Line 62:

Source File:D:\Program Files\IntranetDASHBOARD\wwwroot\ufr\publications\dpe\live\65.aspx Line:60
Stack Trace:
[NullReferenceException: Object variable or With block variable not set.] Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) +927 ASP._65_aspx.__RenderForm1(HtmlTextWriter __output, Control parameterContainer) in D:\Program Files\IntranetDASHBOARD\wwwroot\ufr\publications\dpe\live\65.aspx:60 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +27 System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +44 System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +260 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +241 ASP._65_aspx.__Render__control1(HtmlTextWriter __output, Control parameterContainer) in D:\Program Files\IntranetDASHBOARD\wwwroot\ufr\publications\dpe\live\65.aspx:52 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +27 System.Web.UI.Control.Render(HtmlTextWriter writer) +7 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +241 System.Web.UI.Page.ProcessRequestMain() +1926

Check the following :

Whether the appropriate dll's for data provider such as System.Data.dll,System.Data.OracleClient.dll are added to the references.

And make sure your connection object has connectionString property

Make sure the connection is opened prior to execute statement

|||

...and have you properly created "dbConn"?

connecting to asp.net website

I want to connect to a asp.net website...
does any1 know how to connect queries from the database to the website??
Tahttp://www.123aspx.com/directory.aspx?dir=74 & http://www.devarticles.com/c/a/ASP/Two-Ways-To-Connect-To-SQL-Server-2000-Via-ASP/ for your reference.

Wednesday, March 7, 2012

Connecting to a Named Instance of SQL Server from ASP.Net

Hi,
I have a named instance of SQL Server 2000 called VTMS on a server called
VTMS which resides on a cluster.
I am trying to connect to a database on VTMS from a webapp (URL
http://reports) hosted on a server called RPT (ASP.Net 2.0) using Windows
Authentication.
When I publish this site locally and access it through http://localhost or
publish it on RPT and remote in to RPT and access it through http://reports,
it is able to connect to the database on VTMS. However, if I try to access it
through http://reports from my local machine, it comes up with the error:
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 have the same problem trying to connect to a Reporting Services 2005
report deployed to RPT, but accessing data on VTMS.
My connection strings are as follows:
Data Source:
Data Source=VTMS\VTMS;Initial Catalog=Timesheets
Web.Config:
<add name="HomeDepotON" connectionString="Data Source=VTMS\VTMS;Initial
Catalog=Timesheets;Integrated Security=True"
providerName="System.Data.SqlClient" />
Please help.
You need to enable TCP/IP on MS SQL side.
Right click on SQL server in SQL Server enterprise manager. Tab "General".
Button "Network Configuration"
Make sure you have TCP/IP in enabled protocols.
Also make sure that if there is any firewall between Web server and SQL then
it's open. Also try to ping the SQL server from Web server. Sometimes web
server can not resolve the name of the SQL server due to the network
configuration. Fix it or use IP address.

Connecting to a Named Instance of SQL Server from ASP.Net

Hi,
I have a named instance of SQL Server 2000 called VTMS on a server called
VTMS which resides on a cluster.
I am trying to connect to a database on VTMS from a webapp (URL
http://reports) hosted on a server called RPT (ASP.Net 2.0) using Windows
Authentication.
When I publish this site locally and access it through http://localhost or
publish it on RPT and remote in to RPT and access it through http://reports,
it is able to connect to the database on VTMS. However, if I try to access i
t
through http://reports from my local machine, it comes up with the error:
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 have the same problem trying to connect to a Reporting Services 2005
report deployed to RPT, but accessing data on VTMS.
My connection strings are as follows:
Data Source:
Data Source=VTMS\VTMS;Initial Catalog=Timesheets
Web.Config:
<add name="HomeDepotON" connectionString="Data Source=VTMS\VTMS;Initial
Catalog=Timesheets;Integrated Security=True"
providerName="System.Data.SqlClient" />
Please help.You need to enable TCP/IP on MS SQL side.
Right click on SQL server in SQL Server enterprise manager. Tab "General".
Button "Network Configuration"
Make sure you have TCP/IP in enabled protocols.
Also make sure that if there is any firewall between Web server and SQL then
it's open. Also try to ping the SQL server from Web server. Sometimes web
server can not resolve the name of the SQL server due to the network
configuration. Fix it or use IP address.

Saturday, February 25, 2012

Connecting the ASP.Net to a DB using SQL Query

I have a SQL query that I think it wont work it's:

SELECT break_time, break_rep_no, break_count, break_update_count, break_type, break_group
FROM breaks
WHERE (break_date = @.p1) AND (break_group = @.p2) AND (break_time > @.p3) OR
(break_time < @.P4)
ORDER BY break_time

When I insert this parameters:

@.p1= 7/21/2004
@.p2= 0
@.p3= 9:00 AM
@.p4= 3:00 PM

I get these results:
Break_time rep_no count ucount break_type break_group
9:00:00 AM____2____2_____0________2_________0
9:00:00 AM____2____2_____1________1_________0
10:00:00 AM___1____2_____0________2_________2
11:20:00 AM___2____1_____0________2_________2
1:00:00 PM____2____2_____1________1_________0

Which if you notice not the result I expect look at the (break_group) Column you will find that it brings 0's in addition to 2 which is not expected to appears?

I'm using this query in ASP.Net page Under VB.Net

Me.SqlComm_Chk_Group.Parameters(0).Value = System.DateTime.Today
Me.SqlComm_Chk_Group.Parameters(1).Value = 0
Me.SqlComm_Chk_Group.Parameters(2).Value = tFrom.AddMinutes(59).ToShortTimeString()
Me.SqlComm_Chk_Group.Parameters(3).Value = tTo.AddMinutes(-59).ToShortTimeString()

dr = Me.SqlComm_Chk_Group.ExecuteReader

While dr.Read
tBreakTime = dr(0)
iRepNo = dr(1)
iBreakCount = dr(2)
iBreakUCount = dr(3)
iBreakType = dr(4)
iBreakGreoup = dr(5)

Call Engine(tBreakTime, tFrom, iBreakType, False, iRepNo)
End While
dr.Close()

Where is the problem PLAES?
Thank youParenthesize.


SELECT break_time, break_rep_no, break_count, break_update_count, break_type, break_group
FROM breaks
WHERE (break_date = @.p1) AND (break_group = @.p2) AND ((break_time > @.p3) OR
(break_time < @.P4))
ORDER BY break_time

Even now, I am not sure the code will do what you are looking to do.|||Why I did it before and it works I even try it with OleDB with MSAccess DB But I'm not understand why its not working here every thing seems to be correct|||Depending upon the data in the db and the times you pass, it might APPEAR to work for some data.

Connecting sql server with asp.net


i have created an asp.net application with sql server2000 as backend in my localsystem.

when i deployed the project in other sytem in network,
i receive the following error message.
"sql server does not exsist or access denied"
when i create the same database in local system and change the data source name with local system in configuration file, the application is working.

i do not face this problem with vb.net application as it takes its datasource from network system.

is there anything like i have to give permission for asp.net in sql server network utility.

can anyone sort out the problem

tell me the connection string ?

|||

i have sorted out this issue.

The solution is go to secuity create a new login and give permission to remote server.

Friday, February 24, 2012

Connecting Remote sql server for Asp.net 2.0

Hi all,

I have an application in asp.net 2.0 and iam trying to connect database which is in remote server(Sql server 2000).But iam getting error as follows:

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 know this is because asp.net 2.0 try to connect sql serverexpress by default.i have removed sql server express from my machine,Still iam getting the same error..any body have an idea how to solve this ...

regards

anitha

Hi welcome to asp.net.

You don't have to remove sqlserver express ,it is OK to have both sqlserver 2000 and sqlserver express installed on you machine.

That error means if you are connecting to sqlserver 2005,this failure may be caused by the fact ......but you are not

First make sure your connection string is right,you can check this website:http://www.connectionstrings.com

If that is correctmake sure Named Pipes and TCP/IP network libraries are enabled for the SQL2000 instance and no firewall blocks the connection.

And you can take a look at this :http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=258082&SiteID=1

Friday, February 17, 2012

Connecting ASP.NET to SQLServer,Somebody,Please!

It is now 3 months that we are trying to connect ASP.NET to a SQLServer located on another system.
However we act,we get a fatal error.
We need someone to explain the way of connecting to SQLServer step by step from either VisualStudio.NET or FrontPage 2003.
Our goal is to retrieve records from SQLServer and display them in ASP.NET pages,edit them,and return them to SQLServer.
Thanx in advance.
Mohammad,
in Server Explorer, register the other sql server. Once it is registered, navigate to a table on this server and drag and drop a small table from this server to an aspx page. This will create a sqldataconnection and sqldataadapter. Right-click the sqldata
adapter and select generate dataset. This dataset now needs matching to eg a datagrid, using the dataadpater.fill method and datagrid.bind method. There are loads of examples of this type of thing on the net and in books. Which part in particular do you h
ave problems with? Making the grid editable is more tricky as you'll need to use command objects. If you email me on my address here, I'll post you an example you can use against the northwind database to see how it works.
HTH,
Paul Ibison

Connecting ASP.NET to SQLServer,Somebody,Please!

It is now 3 months that we are trying to connect ASP.NET to a SQLServer loca
ted on another system.
However we act,we get a fatal error.
We need someone to explain the way of connecting to SQLServer step by step f
rom either VisualStudio.NET or FrontPage 2003.
Our goal is to retrieve records from SQLServer and display them in ASP.NET p
ages,edit them,and return them to SQLServer.
Thanx in advance.Mohammad,
in Server Explorer, register the other sql server. Once it is registered, na
vigate to a table on this server and drag and drop a small table from this s
erver to an aspx page. This will create a sqldataconnection and sqldataadapt
er. Right-click the sqldata
adapter and select generate dataset. This dataset now needs matching to eg a
datagrid, using the dataadpater.fill method and datagrid.bind method. There
are loads of examples of this type of thing on the net and in books. Which
part in particular do you h
ave problems with? Making the grid editable is more tricky as you'll need to
use command objects. If you email me on my address here, I'll post you an e
xample you can use against the northwind database to see how it works.
HTH,
Paul Ibison

Connectin ASP.NET to SQL Server 2000, Problem.

Hi
Is there any settings that I must configure to connect an ASP.NET to SQL
Server 2000?
If there is please tell me.
Thanks in advance
Mohammad-Reza Taikandi
You may want to review this;
http://msdn.microsoft.com/library/de...us/dnnetsec/ht
ml/secnetlpMSDN.asp
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
|||Thanks kevin
"Kevin McDonnell [MSFT]" <kevmc@.online.microsoft.com> wrote in message
news:c4gQP66NEHA.3564@.cpmsftngxa10.phx.gbl...
> You may want to review this;
>
http://msdn.microsoft.com/library/de...us/dnnetsec/ht
> ml/secnetlpMSDN.asp
> Thanks,
> Kevin McDonnell
> Microsoft Corporation
> This posting is provided AS IS with no warranties, and confers no rights.
>
>

Connectin ASP.NET to SQL Server 2000, Problem.

Hi
Is there any settings that I must configure to connect an ASP.NET to SQL
Server 2000?
If there is please tell me.
Thanks in advance
Mohammad-Reza TaikandiYou may want to review this;
http://msdn.microsoft.com/library/d...-us/dnnetsec/ht
ml/secnetlpMSDN.asp
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||Thanks kevin
"Kevin McDonnell [MSFT]" <kevmc@.online.microsoft.com> wrote in message
news:c4gQP66NEHA.3564@.cpmsftngxa10.phx.gbl...
> You may want to review this;
>
http://msdn.microsoft.com/library/d...-us/dnnetsec/ht
> ml/secnetlpMSDN.asp
> Thanks,
> Kevin McDonnell
> Microsoft Corporation
> This posting is provided AS IS with no warranties, and confers no rights.
>
>

Sunday, February 12, 2012

Connect to sql server from asp.net web app

Hi,
I have a website on a dedicated web server that can't communicate with a sql server 2000 database sitting behind a firewall. My website is written in asp.net 2 and c# 2 and port 1433 has been opened through the firewall to allow access. On the db server is an admin database set up to use asp.net authentication. I am running Visual Web Dev 2005 Express on the web server to test the application and initially I want to connect to that db and set up my app and asp 'admin' users. For that I would normally use the 'Website/ ASP.NET Configuration' menu option within the IDE. At the moment I just get a connection error:

Server Error in '/asp.netwebadminfiles' Application.

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

Access is denied.

Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.

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

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

Server Error in '/asp.netwebadminfiles' Application.

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

Access is denied.

Description: An error occurred while accessing the resources required to serve this request. The server may not be configured for access to the requested URL.

Error message 401.2.: Unauthorized: Logon failed due to server configuration. Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server. Contact the Web server's administrator for additional assistance.

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

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

Now which server is the problem on - the web server?? What do I need to do to connect with this db? Help! Thanks in advance.

Chris

Look at the IIS logs to see what request generated the 401.2 result code.

Jeff

Connect to SQL Server from ASP.Net application

Hi

I developped an ASP.Net application (with Web Dev Express ) wich attempt to connect to SQL Server Express (installed in the local machine) using Windows authentication.When i launch my application within Web Dev or from IE navigator i receive the following error message : Cannot open the database 'MyDB' login failed for user ServerName\ASPNet.I use SQL Server Management Studio Express to give the user ServerName\AspNet permission to connet to the database but i still receive the same error message.I created a user with strong password within Management Studio with connect permission and attempt to connect from my application using SQL Server authentication i receive the error message : The user 'UserName' is not associated with a trusted connection for SQL Server.Note that when i use the Connect to Database tool in Visual web dev the connection success when i use Windows authentication but fails when i use SQL Server authentication with the same error message above.My OS is WXP Pro SP2

Thanks for any help

Hi,

The message "The user 'UserName' is not associated with a trusted connection for SQL Server." is related to the fact that you are running on WIndows Authentication only. If you want to use SQL Server authentication, you will have to activate that via SQL Server Management Studio, there is an option on the server properties (Make sure you restart the service after changing that setting)

The other problem is that you have to give the user appropiate permissiosn on the database, just giving him connect permissions means that the user will not be able to access the database. He can just connect at server level. You will have to link his server principal to a database principal (by mapping the user to a database user in the appropiate database which has right to gain access to the data). if you don′t have any role to put the user in, you can just create a database user from the server user.


HTH, jens Suessmeyer.

http://www.sqlserver2005.de

|||I am seeing this error too. However I had the system running just fine with asp.net until I installed the microsoft sql server management studio express edition on my machine, now it always comes up with this error. I cannot find what has changed, I have tried to put the aspnet user login into the logins and giving them permission to everything and it still fails. What is the problem here? What is it that the management studio changes that breaks the connectivity?

Thanks,
David.|||

Thanks Jensen for help

I created an account in SQL Server Management Studio with strongly password and i've gived it necessary permissions in the database(connect, read and write) then i configured the server to connect using SQL Server authentication with the account i created , i saved the property and restarted my server like you said.But when i run Mangement Studio again and want to connect to the server using the account above i receive the following error message:

'Cannot connect to MachineName\SQLEXpress

Additionnal informations: A connection was successfully established with the server but then an error occured during the login process(provider:Shared memory, Provider error 0 -There is no process on the other extremity of the pipe. Microsoft SQL Server Error:233'

I d'ont know what this message means.Any idea?

Thanks.

Abdou

|||Hi,

could you please post your connection string in here and indiecate which Data Access components you are using for the connection to the server (wheter you use any old ADO or the new .NET Client)

HTH, jens Suessmeyer.

http://www.sqlserver2005.de
|||

Hello Jensen

I just resolved the connection problem using SQL Server authentication.The problem was that i did'nt enable the 'Enable SQL Server authentication' checkbox in the property page of the server in 'SQL Management Studio'.Now my application works well and i connect to the server using 'SqlClient' class of NetFrameWork like this:

SqlClient conn = new SqlConnection();

string strConn = @."Data Source=(local)\SQLEXPRESS;User ID=UserName;psw=MyPWd;database=MydataBase;";

conn.ConnectionString = strConn;

Conn.Open(); etc...

Thanks of any suggestion.

Abdou

|||

Let me just add the picture if anybody is not knowing where this is located in the management tools:

http://www.sqlserver2005.de/SharedFiles/RemoteConnection.jpg

-Jens Sü?meyer.

Connect to SQL Server from ASP.Net and through firewall

We have a development SQL Server 2000 (running on Win2K SP4) machine that we want to move into our DMZ and access it via the internet and our internal LAN. We have opened the firewall to allow our applications on the LAN to connect to SQL server in the DM
Z.
We connect to SQL Server using the .Net SQLConnection class and using a SQL Server username and password (i.e. sa/password). Also we connect to SQL Server from WinForm and ASP.Net applications using an alias defined using Client Network Utility.
The problem comes when we try to connect to SQL from the LAN from an ASP.Net application. In that case I get "SQL server does not exist..." error. Connecting from a WinForm application works fine.
So to summarise: I run the same connection code (and connection string) on the same client machine to connect to a SQL Server 2000 database via a firewall. The WinForm application works fine, the ASP.Net application throws an error. The connection code an
d connection string are identical.
Can you suggest why this is happening? We have traced the firewall traffic and nothing appears to be blocked.
The connection code follows: (we use an alias for a server name)
'----
Public Shared Function CreateConnection(ByVal aServerName As String, ByVal aDatabaseName As String, ByVal aUserName As String, ByVal aPassword As String) As System.Data.SqlClient.SqlConnection
Dim connectionString As String
Dim connection As System.Data.SqlClient.SqlConnection
connectionString = "server=" + aServerName + ";database=" + aDatabaseName + ";user id=" + aUserName + ";password=" + aPassword
connection = New System.Data.SqlClient.SqlConnection(connectionStri ng)
connection.Open()
Return connection
End Function 'CreateSession
Thanks,
Scott Simms.
Hi Scott,
I learned you ran the same connection code (and connection string) on the
same client machine to connect to a SQL Server 2000 database via a
firewall. The WinForm application works fine, but the ASP.Net application
throws an error.
This problem is strange. Please make sure the server name is correct and
the user account used in the connection string is listed in the SQL Server
logins list.
In Query Analyzer, you can use the following sql statements to check the
logins list on the destination server.
Use master
Select * from syslogins
Please help collect the following information so that I can narrow down
this problem.
1. Please try to create a sample connection web project using the
connection string directly without variables. Please make sure the server
name and user account/password is correct. Did the same problem persist?
2. How did you configure the alias? Did you use named pipes? If so, Please
configure a TCP/IP alias and forcing the connection string to use TCP/IP.
To do this, add the following attribute to the connection string:
"Network Library =dbmssocn"
What's the result?
3. If it is possible, please try the standard SQL client tools, such as
Query Analyzer, connecting to the SQL Server via firewall using the same
sql account. Did the same problem occur again?
I also found the following articles for your reference.
315159 BUG: Named Pipes Do Not Work When Worker Process Runs Under ASPNET
http://support.microsoft.com/?id=315159
328306 INF: Potential Causes of the "SQL Server Does Not Exist or Access
http://support.microsoft.com/?id=328306
I am looking forward to hearing from you soon.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
|||Hello,
How is the issue going on your side? Please try to change the process
acount from "machine" to "SYSTEM" in the machine.config 's <processModel>
element. Does the same problem persist?
I am looking forward to hearing from you soon.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
|||Hello,
How is the issue going on your side? Let us know if you need further
assistance.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
|||Yuan,
We have very simlar issues ast Scott's in our company. Our web server is inside our firewall. And our custom SQL server is inside their firewall. But the network folks told us that both sides was opened. Our custom side opened port 1433. But I just can n
ot connection. Here is the connection string:Password=xxxx;Persist Security Info=True;User ID=xxx;Initial Catalog=DBNAME;Data Source=IDaddress;Network Library=dbmssocn
Can you help?

Connect to SQL Server from ASP.Net and through firewall

We have a development SQL Server 2000 (running on Win2K SP4) machine that we
want to move into our DMZ and access it via the internet and our internal L
AN. We have opened the firewall to allow our applications on the LAN to conn
ect to SQL server in the DM
Z.
We connect to SQL Server using the .Net SQLConnection class and using a SQL
Server username and password (i.e. sa/password). Also we connect to SQL Serv
er from WinForm and ASP.Net applications using an alias defined using Client
Network Utility.
The problem comes when we try to connect to SQL from the LAN from an ASP.Net
application. In that case I get "SQL server does not exist..." error. Conne
cting from a WinForm application works fine.
So to summarise: I run the same connection code (and connection string) on t
he same client machine to connect to a SQL Server 2000 database via a firewa
ll. The WinForm application works fine, the ASP.Net application throws an er
ror. The connection code an
d connection string are identical.
Can you suggest why this is happening? We have traced the firewall traffic a
nd nothing appears to be blocked.
The connection code follows: (we use an alias for a server name)
'----
Public Shared Function CreateConnection(ByVal aServerName As String, ByVal a
DatabaseName As String, ByVal aUserName As String, ByVal aPassword As String
) As System.Data.SqlClient.SqlConnection
Dim connectionString As String
Dim connection As System.Data.SqlClient.SqlConnection
connectionString = "server=" + aServerName + ";database=" + aDatabaseName +
";user id=" + aUserName + ";password=" + aPassword
connection = New System.Data.SqlClient.SqlConnection(connectionString)
connection.Open()
Return connection
End Function 'CreateSession
Thanks,
Scott Simms.Hi Scott,
I learned you ran the same connection code (and connection string) on the
same client machine to connect to a SQL Server 2000 database via a
firewall. The WinForm application works fine, but the ASP.Net application
throws an error.
This problem is strange. Please make sure the server name is correct and
the user account used in the connection string is listed in the SQL Server
logins list.
In Query Analyzer, you can use the following sql statements to check the
logins list on the destination server.
Use master
Select * from syslogins
Please help collect the following information so that I can narrow down
this problem.
1. Please try to create a sample connection web project using the
connection string directly without variables. Please make sure the server
name and user account/password is correct. Did the same problem persist?
2. How did you configure the alias? Did you use named pipes? If so, Please
configure a TCP/IP alias and forcing the connection string to use TCP/IP.
To do this, add the following attribute to the connection string:
"Network Library =dbmssocn"
What's the result?
3. If it is possible, please try the standard SQL client tools, such as
Query Analyzer, connecting to the SQL Server via firewall using the same
sql account. Did the same problem occur again?
I also found the following articles for your reference.
315159 BUG: Named Pipes Do Not Work When Worker Process Runs Under ASPNET
http://support.microsoft.com/?id=315159
328306 INF: Potential Causes of the "SQL Server Does Not Exist or Access
http://support.microsoft.com/?id=328306
I am looking forward to hearing from you soon.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.|||Hello,
How is the issue going on your side? Please try to change the process
acount from "machine" to "SYSTEM" in the machine.config 's <processModel>
element. Does the same problem persist?
I am looking forward to hearing from you soon.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.|||Hello,
How is the issue going on your side? Let us know if you need further
assistance.
Regards,
Michael Shao
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.|||Yuan,
We have very simlar issues ast Scott's in our company. Our web server is ins
ide our firewall. And our custom SQL server is inside their firewall. But th
e network folks told us that both sides was opened. Our custom side opened
port 1433. But I just can n
ot connection. Here is the connection string:Password=xxxx;Persist Security
Info=True;User ID=xxx;Initial Catalog=DBNAME;Data Source=IDaddress;Network L
ibrary=dbmssocn
Can you help?

Friday, February 10, 2012

Connect to SQL Server 2000 through an ASP.NET Web Application

Hi!
I am going to connect to "SQL Server 2000" through an "ASP.NET Web Application". My development environment is "Visual Studio .NET 2003". In my "Toolbox" -> "Data", I drag a "SqlConnection" and drop on the page. It would automatically be named "SqlConnection1". In its "Properties" -> "ConnectionString" -> "<New Connection...>", I would enter my Server Name (SAMIEI), select "Use Windows NT Integrated Security" and Select the Database on the Server (Northwind). Then such Connection String would automatically be generated:

"workstation id=SAMIEI;packet size=4096;integrated security=SSPI;data source=SAMIEI;persist security info=False;initial catalog=Northwind"

Now, I may see "SAMIEI.Northwind.dbo" in the "Data Connections" row of "Server Explorer" with its all "Database Diagrams", "Tables", "Views", "Stored Procedures" and "Functions".
Please take a look at the following code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Try
SqlConnection1.Open()
Catch ex As SqlException
Response.Write(ex.Message)
End Try

End Sub

It would unexceptedly encounter such error:

"Login failed for user 'NT AUTHORITY\NETWORK SERVICE'"

Please tell me the reason. I am much obliged to you for your attention.

Regards!
M.Sadegh Samiei

Hi Sadegh Samiei,

The code looks fine but connecting to SQL will fail because by default ASP.NET application will run under ASP.NET default user security context or IIS Anonymus user context. So inorder to run in others or in your security context goto web.config file set the impersonate attribute of identity element to true to run under login user security context mode if you want to run under specific user security context mode then username and password attributes in identity element

<configuration>

<system.Web>

<identity impersonate="true"/>

</system.Web>

</configuration

Regards,

Big Smile [:D]

|||

Hi,

The 'NT AUTHORITY\NETWORK SERVICE' is the ASP.NET user process used under Win Server 2003 and IIS 6. When you check the database you are working with, "Northwind", you may see that a user named ASPNET (the "user" for pre Win Server 2003) already has the necessary permissions, but you need to provide the correct permissions for 'NT AUTHORITY\NETWORK SERVICE'. If you don't have the that user set up on the database with proper permissions, you'll get a login error message - as you did. You can use SQL Server 2000's Enterprise manager to do the setup. Or you can use method suggested in the other reply. BRN..