Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

mssql_select_db(): supplied argument is not a valid MS SQL-Link resource

Posted on 2006-05-17
11
Medium Priority
?
5,602 Views
Last Modified: 2013-12-12
I get the following results from a query I have made.


Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 10

Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

My connection to the DB seems to work fine. Here is the script...

<?php require_once('connection.php'); ?>
<?php
$maxRows_rsUsers = 10;
$pageNum_rsUsers = 0;
if (isset($_GET['pageNum_rsUsers'])) {
  $pageNum_rsUsers = $_GET['pageNum_rsUsers'];
}
$startRow_rsUsers = $pageNum_rsUsers * $maxRows_rsUsers;

mssql_select_db($database_assets, $assets);
$query_rsUsers = "SELECT * FROM asset_assets ORDER BY employee_assets ASC";
$query_limit_rsUsers = sprintf("%s LIMIT %d, %d", $query_rsUsers, $startRow_rsUsers, $maxRows_rsUsers);
$rsUsers = mssql_query($query_limit_rsUsers, $assets) or die(mssql_error());
$row_rsUsers = mssql_fetch_assoc($rsUsers);

if (isset($_GET['totalRows_rsUsers'])) {
  $totalRows_rsUsers = $_GET['totalRows_rsUsers'];
} else {
  $all_rsUsers = mssql_query($query_rsUsers);
  $totalRows_rsUsers = mssql_num_rows($all_rsUsers);
}
$totalPages_rsUsers = ceil($totalRows_rsUsers/$maxRows_rsUsers)-1;
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/template.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->


<link href="stlye.css" rel="stylesheet" type="text/css">
</head>

<body>
<table width="100%" height="95"  border="0" class="nugheader">
  <tr class="nugget">
    <th scope="col"><p class="style1"><img src="logo.gif" width="267" height="73"></p>
    </th>
  </tr>
</table>
<table width="100%"  border="0">
  <tr valign="top" class="nugget">
    <th width="20%" height="791" valign="top" scope="row"><table width="100%"  border="0" class="nugget">
      <tr>
        <th scope="row"><a href="users.php">User List</a></th>
      </tr>
      <tr>
        <th scope="row"><a href="insert.php">User Entry</a></th>
      </tr>
    </table>
    <table width="100%"  border="0">
      <tr class="nugget">
        <th scope="row">Search</th>
      </tr>
      <tr>
        <th scope="row"><form action="search.php" method="get" name="form1" class="nugget">
          <input type="submit" name="Submit" value="Submit">
          <input name="SearchString" type="text" id="SearchString">
        </form></th>
      </tr>
    </table></th>
    <td width="80%"><!-- InstanceBeginEditable name="Main" -->
      <table width="100%" border="1">
        <tr>
          <td>Employee</td>
          <td>PC Name</td>
          <td>Model</td>
          <td>Manufacturer</td>
          <td>Notes</td>
          <td>Date</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php do { ?>
        <tr>
          <td><?php echo $row_rsUsers['employee_assets']; ?></td>
          <td><?php echo $row_rsUsers['pcname_assets']; ?></td>
          <td><?php echo $row_rsUsers['model_assets']; ?></td>
          <td><?php echo $row_rsUsers['manufac_assets']; ?></td>
          <td><?php echo $row_rsUsers['notes_assets']; ?></td>
          <td><?php echo $row_rsUsers['date_assets']; ?></td>
          <td><a href="update.php?id_assets=<?php echo $row_rsUsers['id_assets']; ?>">Update</a></td>
          <td><a href="delete.php?id_assets=<?php echo $row_rsUsers['id_assets']; ?>">Delete</a></td>
        </tr>
        <?php } while ($row_rsUsers = mssql_fetch_assoc($rsUsers)); ?>
      </table>
    <!-- InstanceEndEditable --></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>
<?php
mssql_free_result($rsUsers);
?>
0
Comment
Question by:kwestion
11 Comments
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16700432
>>>My connection to the DB seems to work fine.<<<

all the errors you got is because your connection to the db is not working in the first place !!!

there no established connection between ur script and the db

can u post 'connection.php' here ?
0
 
LVL 6

Expert Comment

by:pritaeas
ID: 16702282
Probably $assets is out-of-scope, assuming it is used in connection.php like:

$assets = mssql_connect (HOST, USER, PASS);

Either that or the connect failed for another reason. You can check mysql_error after the connect (if it fails).
0
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 16707372
>>>Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 10

This shows the connection has not been established


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:kwestion
ID: 16708076
Hsre is connection.php

<?php
# FileName="Connection_php_mssql.htm"
# Type="MSSQL"
# HTTP="true"
odbc_connect("Assets","sa","password");
?>
0
 

Author Comment

by:kwestion
ID: 16708799
I forgot some variables.

<?php
# FileName="Connection_php_mssql.htm"
# Type="MSSQL"
# HTTP="true"
$database_assets = "assets";
$assets = odbc_connect("Assets","sa","Th3Dever");
?>
0
 
LVL 16

Accepted Solution

by:
dr_dedo earned 2000 total points
ID: 16710294
try this
<?php

$connection_string = 'DRIVER={SQL Server};SERVER=<servername>;DATABASE=<databasename>';

$user = 'username';
$pass = 'password';

$connection = odbc_connect( $connection_string, $user, $pass );

?>
0
 

Author Comment

by:kwestion
ID: 16710849
I had been using a DSN, because I cannot seem to connect otherwise.

The username and password are correct, and for the servername, I try the actual name, and localhost. I am using MSSQL Express 2005. Unfortunately, I cannot just use a MySQL DB for this application, or I'd be done by now. :)

Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied., SQL state 08001 in SQLConnect in C:\Web Services\Apache Group\Apache2\htdocs\itassets\connection.php on line 10
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16711040
some tips from here and there
------------------------------------------------------------
The recently released SQL Server 2005 Express will work with MSSQL functions. Here are some caveats:
1) The version of ntwdblib.dll supplied with PHP will not work with Server 2005 (Win32 only). You must use a newer version. The version supplied with SQL Sever 2000 (2000.80.194.0) seems to work well.
2) You must set up mssql_connect to reference the server AND the instance name, eg:
mssql_connect("MyPC\SQLEXPRESS","MyUser","MyPwd");
Although the MSSQL functions work, you might want to consider using the new 'pdo_odbc' (PHP 5.1) with SQL Server 2005 Express for any new code you are writing.
------------------------------------------------------------
0
 

Author Comment

by:kwestion
ID: 16711366
Thanks, I beleive that got me connected. Downloaded it from Webzilla.

Now I am left with this.

Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near 'LIMIT'. (severity 15) in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

Warning: mssql_query() [function.mssql-query]: Query failed in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13

Fatal error: Call to undefined function mssql_error() in C:\Web Services\Apache Group\Apache2\htdocs\itassets\test.php on line 13




Here is the connection page:
<?php

$server = "SPL-NJ-L395\SQLEXPRESS";

$user = 'sa';
$pass = 'xxxxxx';

$database_assets = "assets";

$assets = mssql_connect( $server, $user, $pass) or trigger_error(mssql_error(),E_USER_ERROR);

?>


And here is line 13:
$rsUsers = mssql_query($query_limit_rsUsers, $assets) or die(mssql_error());

0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16711441
check your SQL syntax, there error is there, try it in msSQL server itself to check its syntax. i don't know if the keyword limit is supported in mssql or not!
0
 

Author Comment

by:kwestion
ID: 16711902
It appears I have to play with mssql queries a bit, but its up an running. Thanks.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question