Welcome Guest, Not a member yet? Register   Sign In
how can I connect to MS SQL Server 2005?
#1

[eluser]chmod[/eluser]
I have setup the MS SQL Serve 2005 with suportting remote connect,and the auth is OK(username:liujun,pass:123456).
and I test connect with freetds's tsql under Linux system.
so,
I create a database demo,and the table baseinfo.
test result is below:

==================================
soapserver# ./tsql -H 192.168.1.134 -p 1433 -Uliujun
locale is "C"
locale charset is "US-ASCII"
Password:

1> select * from baseinfo;
2> go
accountid account password pointnum lastaddpointtime LastAddPointNum
1 liu1084 123456 10 May 06 2008 12:00AM 3
===================================
test is sucessful.

Using CI connect to DB like these:
controller:
----------------
function index(){
$active_group = "mssql";
$active_record = TRUE;

$db['mssql']['hostname'] = "192.168.1.134";
$db['mssql']['username'] = "liujun";
$db['mssql']['password'] = "123456";
$db['mssql']['database'] = "demo";
$db['mssql']['dbdriver'] = "mssql";
$db['mssql']['dbprefix'] = "";
$db['mssql']['pconnect'] = TRUE;
$db['mssql']['db_debug'] = TRUE;
$db['mssql']['cache_on'] = FALSE;
$db['mssql']['cachedir'] = "";
$db['mssql']['char_set'] = "utf8";
$db['mssql']['dbcollat'] = "utf8_general_ci";

$query = $this->db->get('baseinfo');

if ($query->num_rows() > 0){
foreach ($query->result() as $row){
echo $row->account_id;
echo $row->username;
}
}
}


the error is below:
--------------------------

An Error Was Encountered

Error Number: 1146

Table 'demo.baseinfo' doesn't exist

SELECT * FROM (`baseinfo`)


I found the connect to my local MySQL server ,not 192.168.1.134 mssql server. Why not?

in the autoload config,i use default connect is mysql:
and database.php is like these:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "pass";
$db['default']['database'] = "demo";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";


is there any error with me?
#2

[eluser]chmod[/eluser]
any one have a good idea?
#3

[eluser]JulianM[/eluser]
Anyone else had the same problem connecting to SQL Server?

I'm considering to use CodeIgniter for a new project in a Windows box (unfortunately) with SQLServer 2005.

The client initially wanted to go through DotNetNuke with VB.NET (ugh!). But if CodeIgniter works fine with SQL Server 2005 (DBMS in a separated server), I think I will be able to convince them to use PHP with CodeIgniter framework.

Any advice is appreciated.

Thanks.


[quote author="chmod" date="1210249539"]any one have a good idea?[/quote]
#4

[eluser]whobutsb[/eluser]
I have a couple of different CI Applications all running off of MSSQL Server 2005 Databases. Everything for the most part runs great. The one thing I highly recommend is downloading Gusa's MSSQL_DB_EXT Driver, you can find it here: http://ellislab.com/forums/viewthread/81849/

It helps with the active record limit query, which natively MSSQL doesn't support. The one thing I found with it is you can't use advance sql statements with joins or groupbys. So I usually break my queries into two parts. One to get the limited row IDs and then a second query that actually gets the information.

Other than that minor little thing it works like a charm. And MSSQL Server Management Studio is actually a pretty good application to manage your DB.

@chmod- Are you placing your server parameters into the config/database.php file?
#5

[eluser]cwt137[/eluser]
Hello,

Your first problem is that it is trying to connect to mysql. Put this code in to change the driver to mssql:

Code:
$db['default']['dbdriver'] = "mssql";

Also, you need the mssql PHP extension installed. You can check phpinfo() to see if you have it installed. If you don't have it installed and you are running Fedora/RHEL/Centos, look for either the php-extras or the php-mssql rpm package in the regular repo. or the EPEL repo. Else, look in your distro's repository or compile it in. If you don't want to do all that work set up a DSN and use ODBC.




Theme © iAndrew 2016 - Forum software by © MyBB