none
WCF Services with database

    Question

  • Hi,

    I'm trying to create a server using WCF. Under VS 2012 I've created a "WCF server" and added a Sql Server Database (automatically in App_data).

    I've created a client.

    I've tried to publish my server on my server (basic offer from Ikoula). I can use services and my client receives the data for this example :

    public string GetData(string value)
            {
                return "You entered :"+value;
            }

    But i can't manage to open my database with this code :

    public List<Produit> GetAllProduits()
            {
                try
                {
                    List<Produit> list = new List<Produit>();
                    using (SqlConnection SqlConn = new SqlConnection(strConnexion))
                    {
                        SqlConn.Open();
                        
                        SqlConn.Close();
                    }
    
                    return list;
                }
                catch (Exception erreur)
                {
                    List<Produit> list = new List<Produit>();
                    Produit p = new Produit();
                    p.Nom = erreur.Message+"connexion:"+strConnexion;
                    list.Add(p);
                    return list;
                }
            }

    I have always the same error :

    ""A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

    I've tried all this connection strings (and many others):

    public static string strConnexion = "Data Source=(local);Initial Catalog=BDD.mdf;Integrated Security=True;";
            public static string strConnexion = @"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\BDD.mdf;User Instance=true";
            public static string strConnexion = "Data Source=.\\SQLEXPRESS;Initial Catalog=BDD;Integrated Security=True;User Instance=True";

    The first one give me this error :

    ""Login failed for user 'VMHEB49016\\IWPD_35(zstu887)'."

    I can't manage to fix this error, I've found a lot of topics on google but never found how to fix this problem. I'm sure this is not a big issue, I should have missed something...

    Thank you

    PS: I hope this is the right forum to post this.

    Monday, February 04, 2013 6:57 PM

All replies

  • Hello,

    I suppose that you are using a SQL Server Express Edition but which version ( 2005,2008,2008 R2,2012 ).

    I think i will move your thread towards the SQL Server Express forum ( a move from a moderator has 3 advantages : 1) no thread to recreate 2) no lost posts 3) no thread let dying in a forum which is not the most appropriate one )

    Some remarks :

    1st connection string : false except if you have created a default instance ( i prefer tell no-named instance, that's to say the name of the instance has been completely rubbed off , very rare even if i have tested it ( only possible since SQL Server 2008 )

    2nd error in the 1st connection string : Initial Catalog = name of the database not the name of the datafile of the database ( i think that the name of your database is BDD )

    For the other connection strings , the User Instance feature is depreciated since 2008 and i suggest to avoid its use ( even with all the explanations from Mike Wachal gave me on the SQL Server Express forum, i don't master this feature which is really tricky ).Moreover, the User Instance feature is only supported by the Express Editions and you will have many problems if you have to upgrade to an edition not free like Standard or Web,...Don't forget that user instance forbids any connection to a remote instance ( that's to say if your application is not running on the same computer that where the SQL Express instance is installed ) or with SQL Server authentification.

    For the 2nd connection string, as the datafile of the database is in a special folder , except the Windows user who has created this file has access to the database, which limits seriously the interest of this way

    I am astonished by your error message "'VMHEB49016\\IWPD_35(zstu887)"  : curious name of user with the use of "(" and ")".

    We are waiting for more explanations from you to move your thread towards the SQL Server Express Forum ( usually, i prefer to wait for the agreement of the the original poster that's to say you before doing the move )

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Monday, February 04, 2013 9:50 PM
  • Hi,

    I've just installed VS 2012 Ultimate, it installed SQL server 2012 (don't know if it's express or not).

    I've contacted also the hoster of my server and they answered me i had to create a connectionstring like this :

    <connectionStrings>
        <add name="nameYouWant"
            connectionString="Data Source=127.0.0.1;Initial Catalog=databaseName;User Id=userid;Password=passwd;"
            providerName="System.Data.SqlClient" />
      </connectionStrings>


    But i can't manage to create a user, VS doesn't show me any interface only TRANSACT-SQL (if I go to object>Security>Connexions>Add).

    So I can't do this : http://msdn.microsoft.com/fr-fr/library/aa337562.aspx

    I've also tried to create an account using TRANSACT SQL :

    In server instance :

    CREATE LOGIN shcooper 
       WITH PASSWORD = 'Baz1nga' MUST_CHANGE

    But I have an error : 'Une erreur s'est produite lors de l'exécution du lot.' which means "an error happened"

    In database instance :

    CREATE USER [shcooper]
    WITH PASSWORD = 'Bas1ngwa'
    GO

    GRANT CONNECT TO [shcooper]

    Error :

    SQL71501 :: Autorisation contient une référence non résolue à Objet [scooper].
    SQL46096 :: Impossible de fournir le paramètre PASSWORD pour des utilisateurs qui ne peuvent pas s'authentifier dans une base de données.

    By default the database is using Windows Authentification, I'm just trying to add a user but I can't.

    Also, I don't understand the difference between the server instance and the database instance (which contains all my tables), when I'll deploy my server, both are deployed ? I should configure Server Instance ? Or is it just used locally ?


    Yes you can move this topic.

    Thanks,


    • Edited by r0seBa Tuesday, February 05, 2013 9:31 AM
    Tuesday, February 05, 2013 9:26 AM
  • In fact I just can't create new users so I can't configure my webconfig..
    Wednesday, February 06, 2013 1:09 PM