Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
duanecwilson
Constraint Violating Yak Guru
273 Posts |
Posted - 2009-07-27 : 10:15:18
|
This is incredibly elusive and frustrating. It shouldn't be. It is all Microsoft products which should work together.I have created a few test sites on localhost in ASP using either VB or C# (very simple). They worked fine after playing around wiht IIS for a while (I didn't even know what that was). Then I tried connecting to the SQL Server database through Windows Authentication. It was on another server on the intranet. Again, after some playing around, I got the simple SQL Server page to work on localhost.Then, I got the simple sites to work on another company webserver on the intranet after the webmaster played around with settings.My problem is that no matter what I do, I cannot get a simple query to run that has a SQL Server query. Everyone can get into SQL Server through Windows Authentication. I even tried creating a special SQL Server acoount for ASP users and put the information in web.config. Just pure nothing. I do have Access front ends that can get into this database, but nothing ASP. It's hard for me to explain all this here, but please help me. I don't understand the web.config file or the IIS settings or where to set them (on the SQL Server computer, the computer with the website, or everyone's PCs or what) I just want to process a query against the SQL Server database on the network.Duane |
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-07-27 : 11:14:14
|
why not paste some sample code, in .net you put your connection string in you web.config file and your queries are best placed in your classes |
|
|
duanecwilson
Constraint Violating Yak Guru
273 Posts |
Posted - 2009-07-27 : 11:51:31
|
quote: Originally posted by afrika why not paste some sample code, in .net you put your connection string in you web.config file and your queries are best placed in your classes
Thank you for the response. Here is the contents of my web.config file:<?xml version="1.0"?><configuration> <configSections> <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /> <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /> </sectionGroup> </sectionGroup> </sectionGroup> </configSections> <appSettings/> <connectionStrings> <add name="ComputerInventoryDCWConnectionString" connectionString="Data Source=IHCMYS01;Initial Catalog=ComputerInventoryDCW;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="ComputerInventoryDCWConnectionString2" connectionString="Data Source=IHCMYS01;Initial Catalog=ComputerInventoryDCW;User ID=ASP.Net_Login;Password=aspuser" providerName="System.Data.SqlClient" /> </connectionStrings> <system.web> <compilation debug="false"> <assemblies> <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> </assemblies> </compilation> <authentication mode="Windows" /> <pages> <controls> <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </controls> </pages> <httpHandlers> <remove verb="*" path="*.asmx"/> <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/> </httpHandlers> <httpModules> <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </httpModules> </system.web> <system.codedom> <compilers> <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="WarnAsError" value="false"/> </compiler> <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <providerOption name="CompilerVersion" value="v3.5"/> <providerOption name="OptionInfer" value="true"/> <providerOption name="WarnAsError" value="false"/> </compiler> </compilers> </system.codedom> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules> <remove name="ScriptModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> </modules> <handlers> <remove name="WebServiceHandlerFactory-Integrated"/> <remove name="ScriptHandlerFactory" /> <remove name="ScriptHandlerFactoryAppServices" /> <remove name="ScriptResource" /> <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </handlers> </system.webServer> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/> </dependentAssembly> </assemblyBinding> </runtime></configuration>-----------------I took the machine generated comments out to shorten it a little.----------------------------------Here is the contents of the default.aspx file:-----------------<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <div> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmpID" DataSourceID="MachineTest2DS"> <Columns> <asp:BoundField DataField="EmpID" HeaderText="EmpID" InsertVisible="False" ReadOnly="True" SortExpression="EmpID" /> <asp:BoundField DataField="EmpNumber" HeaderText="EmpNumber" SortExpression="EmpNumber" /> <asp:BoundField DataField="Last" HeaderText="Last" SortExpression="Last" /> <asp:BoundField DataField="First" HeaderText="First" SortExpression="First" /> <asp:BoundField DataField="OfficeName" HeaderText="OfficeName" SortExpression="OfficeName" /> <asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" /> <asp:BoundField DataField="DeptID" HeaderText="DeptID" SortExpression="DeptID" /> <asp:BoundField DataField="Company" HeaderText="Company" SortExpression="Company" /> <asp:BoundField DataField="MachineNumber" HeaderText="MachineNumber" SortExpression="MachineNumber" /> <asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" /> <asp:BoundField DataField="MachineType" HeaderText="MachineType" SortExpression="MachineType" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="MachineTest2DS" runat="server" ConnectionString="<%$ ConnectionStrings:ComputerInventoryDCWConnectionString2 %>" SelectCommand="SELECT Employees.EmpID, Employees.EmpNumber, Employees.Last, Employees.First, Office.OfficeName, dbo_Department.Department, Employees.DeptID, dbo_Company.Company, Machine.MachineNumber, ModelLU.Model, MachineType.MachineType FROM Machine INNER JOIN Employees ON Machine.EmpID = Employees.EmpID INNER JOIN MachineType ON Machine.MachineTypeID = MachineType.MachineTypeID INNER JOIN ModelLU ON Machine.ModelID = ModelLU.ModelID INNER JOIN Office ON Employees.OfficeID = Office.OfficeID INNER JOIN dbo_Company ON Employees.CompanyID = dbo_Company.ID INNER JOIN dbo_Department ON Employees.DeptID = dbo_Department.ID WHERE (NOT (Employees.Last LIKE N'Test%')) AND (NOT (Employees.EmpNumber LIKE N'ZZZ%')) ORDER BY Employees.Last, Employees.First, MachineType.MachineType"> </asp:SqlDataSource> <br /> <br /> <br /> <br /> </div> </form></body></html>-----------------And here is the C# file (default.aspx.cs):-----------------using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { }}-----------------I appreciate you looking at this. Almost all of this code was generated by Visual Studio Web Developer 2008 and it just displays or is supposed to display a datagrid with a query behind it. It works fine on localhost, but when I used the options to "copy web site" and put it on the webserver, I got this error.Duane |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-07-28 : 03:42:12
|
Can you remove the SQLDatasource & then fill the resultset of the query into a dataset or a datatable & then trying binding it to the grid lk thisgrid.datasource=dataset |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-07-28 : 04:26:33
|
your connection string is wrongsee www.connectionstrings.com |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2009-07-28 : 07:28:48
|
quote: Originally posted by afrika your connection string is wrongsee www.connectionstrings.com
But why do u think it is wrong??<add name="ComputerInventoryDCWConnectionString" connectionString="Data Source=IHCMYS01;Initial Catalog=ComputerInventoryDCW;Integrated Security=True"providerName="System.Data.SqlClient" /><add name="ComputerInventoryDCWConnectionString2" connectionString="Data Source=IHCMYS01;Initial Catalog=ComputerInventoryDCW;User ID=ASP.Net_Login;Password=aspuser"providerName="System.Data.SqlClient" /> |
|
|
duanecwilson
Constraint Violating Yak Guru
273 Posts |
Posted - 2009-07-28 : 09:13:31
|
Thank you for the responses yesterday. I created this simple test aspx page in another folder by itself with no web.config file and it worked fine. Just gave me a little text grid with some data in it, but it works all over the network. How can I translate this functionality to the bigger test above? Especially since Visual Studio produced this code, I want to know how to configure it so it won't force me to go behind it like this. I created this one in Notepad. Here it is:<%@ Import Namespace="System.Data.SqlClient" %><%@ Page Language="C#" %><script runat="server"> protected void Page_Load(Object sender, EventArgs e) { SqlConnection con = null; SqlCommand cmd = null; try { con = new SqlConnection("server=IHCMYS01;uid=ASP.Net_Login;" + "pwd=aspuser;database=ComputerInventoryDCW"); cmd = new SqlCommand("SELECT * FROM Employees", con); con.Open(); grid.DataSource = cmd.ExecuteReader(); grid.DataBind(); } catch (Exception err) { message.Text = "<p><font color=\"red\">Err: " + err.Message + "</font></p>"; } finally { if(con != null) con.Close(); } }</script><html><head> <style> body { font-family:Verdana; font-size:12pt; } </style></head><body> <asp:datagrid id="grid" runat="server" /> <asp:label id="message" runat="server" /></body></html>Duane |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-07-28 : 12:12:56
|
I dont think its a good practice to keep your connection in your code behind.Keep it in your web.config and reference it through your class. I can give you some examples if you want |
|
|
duanecwilson
Constraint Violating Yak Guru
273 Posts |
Posted - 2009-07-28 : 14:46:32
|
If you can do that, I would appreciate it. I don't really understand any of this that well, yet. I am new at it. I just had to get something working at all.Duane |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2009-08-17 : 06:26:35
|
sorry this is coming late.we had a few issues with our server.1. Your connection string in the web.config is okstep 2 you have to reference it in your class e.g.2. Create a class, which would be stored in the app_code directory in order to execute e.g. using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;using System.Web.Configuration;using System.ComponentModel;[DataObject(true)]public class myclass{ [DataObjectMethod(DataObjectMethodType.Select, true)] public DataSet myclass_data(string username) { string ehioze = "select * from yourtable "; string ConnectionString = WebConfigurationManager.ConnectionStrings["webconfig_variable"].ConnectionString.ToString(); using (SqlConnection connection = new SqlConnection(ConnectionString)) { SqlCommand command = connection.CreateCommand(); command.CommandText = ehioze; command.Connection = connection; SqlDataAdapter adapter = new SqlDataAdapter(command); DataSet categoriesDataSet = new DataSet(); adapter.Fill(categoriesDataSet); return categoriesDataSet; /* connection.Open(); SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection); return reader;*/ } }} |
|
|
|
|
|
|
|