Showing posts with label website. Show all posts
Showing posts with label website. Show all posts

Tuesday, March 27, 2012

cant get data from sql

I'm adding a few simple pages to our existing website to be able to keep all of our vendor information. Most of the rest of the website is using a Microsoft Access database. This new portion though is being built using a SQL database. For some reason though I seem to be unable to pull any information from the sql database, I've added the sql connection string into the main web.config file, as well as importing all the needed namespaces. I don't get any errors when I view the pages, but also get nothing from the database. What might I need to look at for this issue, I'm confused about why I can't get any data from the db. Any help is greatly appreciated.

Hey,

What might the code you are using look like?

|||

here's my connection string in the web.config -- minus user id and password, and an example of how I'm trying to pull data

<

addname="SQLConnString"connectionString="Data Source=UELIIS;Initial Catalog=ITtech;Persist Security Info=True;User ID=*****;Password=*****"providerName="System.Data.SqlClient"/>

PrivateSub GetMaxVendorNum()

Dim NextVendorNumAsString

strSql =

"SELECT MAX(VendorNum) + 1 AS Expr1FROM Vendor"

dr = GetDataReader(strSql, strConn)

If dr.Read()Then

NextVendorNum = dr(

"Expr1").ToString

lblVendorNum.Text = NextVendorNum.ToString

EndIfEndSubPublicSharedFunction GetDataReader( _ByVal SQLStatementAsString, _ByVal ConnectionStringAsString)As SqlDataReaderDim drAs SqlDataReaderDim cmdAsNew SqlCommandWith cmd

.Connection = _

New SqlConnection(ConnectionString)

.Connection.Open()

.CommandText = SQLStatement

dr = .ExecuteReader(CommandBehavior.CloseConnection)

EndWithReturn drEndFunction

Thanks for your help

|||

Hey,

I tried your query, and that worked for me. The only thing I can think of is the fact that you are returning the data reader and something is happening in between. Is the problem that you are getting no entries or that you are getting an error thrown.

|||I'm just not getting any entries, just blank fields|||The really crazy thing is that on my first page I'm using a sqldatasource to populate a gridview and it pulls and displays the information with no problem. Its using the same connection string as my other pages.|||

well i've narrowed it down to the fact that my page_load event isn't firing for some reason, I even tried to put a script tag in the .aspx page and place it there instead of a code behind page but still nothing, can't even put text into the error label. Here's some of my code snippets that may help troubleshoot problem.

<%

@.PageLanguage="VB"AutoEventWireup="false"CodeFile="VendorEdit.aspx.vb"Inherits="VendorEdit" %>

Partial

Class VendorEdit

Inherits

System.Web.UI.Page

.... CODE.....

end class

Ask if you need to see any code or need more information. Thanks for your help.

|||

Hi,

Thanks for your code.

I tried it on my machine and it works fine. The only problem seems that I cannot see any code that your DataReader is binding to. Did you set it as the datasource of a GridView?

If so, please also call GridView.DataBind() after it has been set as the DataSource.

HTH.

|||

could you post your page_load event code make sure its something like following

Protected

Sub Page_Load(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.LoadEndSub

handles me.load is must.

thanks,

satish.

Tuesday, February 14, 2012

Cant Connect to remote server, my app works in local only??

Hello,
i've developed a website using VB.NET, and SQL SERVER 2K, in my dev environment works properly (SQL Server and WEB SERVER are in the same machine).
When i put everything in the target machine, where the webserver is but not the sql, i get the following error:
Sql SErver does not exist or access denied

I've tried so many ways to do this, ODBC, ADO.NET, OLEDB....and everything ends in the same error.
Also if i try to connect with ODBC (from odbc manager) it seems to work (test connection succesfull), but in asp.net nothing works.
I've tried to access the server with:
INSTANCE_NAME
\SERVER_NAME\INSTANCE_NAME
IP,PORT

I think (they are checking this), that the auth mode is set to MIXED MODE.

Any idea to save my life?? ;)

Thanks pplYour reference to the server in your ADO connection string should be:

ipaddressofserver\instancename (i.e., 206.152.125.6\instance1 )

If you are using SQL Authenticiation, which you should, then you need to reference the {uid} and {password} properties.
I would be willing to bet that your SQL Installation is set the Mixed Mode.

HTH

Sunday, February 12, 2012

Cant connect to database

I am developing my first website for my boss. I am trying to connect to an access database which I have created a DSN for on the server. I am using the following code sample...

//Connection String 1

string dsn_name ="access_WALLINVEN.dsn";

string sDSNDir = Server.MapPath("_dsn");

string connectstr = ("Data Source="

+ (sDSNDir + ("\\" + dsn_name)));

//Connection String 2

string connectstr ="Data Source=/jwallpaint/_dsn/access_WALLINVEN.dsn;Uid=jwallpaint;Pwd=J2512wall;";

string commandString ="Select * from Inventory";

//Pass strings to sqlDataAdapter constructor

SqlDataAdapter dataAdapter =newSqlDataAdapter(commandString, connectstr);

//Create a dataset

DataSet dataSet =newDataSet();

//fill the dataset object

dataAdapter.Fill(dataSet,"Inventory");

//Get the table from the dataset

DataTable dataTable = dataSet.Tables["Inventory"];

//Bind to the gridview

GridView1.DataSource = dataTable;

GridView1.DataBind();

For Connection String 1 I get the error of...

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

For Connection String 2 I get the error of...

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 am not sure which connection string to use either...

It is strange to me that I get this error talking about SQL Server when I am trying to reach my Access database.....Any Help?? Thanks...

Connection string forFile DSN:

"FILEDSN=c:\myData.dsn;Uid=myUsername;Pwd=;"

Checkhttp://www.connectionstrings.com/ for more connection strings.